Note that there are some explanatory texts on larger screens.

plurals
  1. POFxCop: Returning Matrix as Property (C#)
    primarykey
    data
    text
    <p>I have a static class 'Defaults' which shall hold default matrices that are forwarded to an interface that asks for <code>double[][]</code> in the end. So far I simply put static properties in this class that return <code>double[][]</code>s.</p> <p>Now to make this conform to our company's coding standards, the code must comply to FxCop's rule <a href="http://msdn.microsoft.com/en-US/library/0fss9skc%28v=VS.100%29.aspx#3" rel="nofollow noreferrer">CA1819</a>, which won't allow me to return a jagged array from a property like I did. And instead of arrays, I shall return <code>IList</code> or <code>IEnumerable</code> (as discussed <a href="https://stackoverflow.com/questions/1274914/is-it-bad-form-to-return-arrays-in-c-should-i-return-listt">here</a>).</p> <p>"Fair enough" I thought, so I implemented the property to return <code>IList&lt;IList&lt;double&gt;&gt;</code> (although nested types are uncool too). However, as I said, the interface which I need to work with asks for <code>double[][]</code> matrices in the end.. I have no idea how to get this list of lists into an array of arrays <strong>without explicitly converting back each list</strong>. Of course, I could, but that would create an insane amount of overhead, especially since I don't even access those matrices - I only pass them through to the interface.</p> <p>(PS: I know, it's the Interface's fault, but at the moment we can't change that.)</p> <p>Edit: I found out that using <code>ILists&lt;IList&lt;double&gt;&gt;</code> donesn't help anyway, since it violates <a href="http://msdn.microsoft.com/en-us/library/ms182144.aspx" rel="nofollow noreferrer">CA1006</a>. The easy solution that I took to make FxCop shut up was to make the properties internal. Anyway, the nicer solution is stated below. Alternatively, one may consider to use an indexed property, which is a bit messy in C# though.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload