Note that there are some explanatory texts on larger screens.

plurals
  1. POCA1819: Properties shouldn't return arrays - What is the right alternative?
    primarykey
    data
    text
    <p>I encountered this FxCop rule before and wasn't really content with how to solve violations (<a href="https://stackoverflow.com/questions/3324053/why-properties-that-return-arrays-are-prone-to-code-inefficiencies">thread1</a>, <a href="https://stackoverflow.com/questions/6596166/fxcop-returning-matrix-as-property-c">thread2</a>). I now have another case where I need to correct violations of the <a href="http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&amp;l=EN-US&amp;k=k%28PROPERTIESSHOULDNOTRETURNARRAYS%29;k%28TargetFrameworkMoniker-%22.NETFRAMEWORK,VERSION=V4.0%22%29&amp;rd=true" rel="nofollow noreferrer">CA1819</a> kind.</p> <p>Specifically, I have an algorithm-library that performs some analytic calculations on a curve (x,y), with a public "input object" like this:</p> <pre><code>public class InputObject { public double[] X { get; set; } public double[] Y { get; set; } // + lots of other things well } </code></pre> <p>This object's X and Y properties are used in hundreds of locations within library, typically using indexes. The input object is never altered by the algorithms, but actually it shouldn't matter if so. Also, <code>.Length</code> is called pretty frequently. It's a mathematical library, and <code>double[]</code> is kind of the standard data type in there. In any case, fixing CA1819 will require quite some work.</p> <p>I thought about using <code>List&lt;double&gt;</code>, since Lists support indexing and are quite similar to arrays but I'm not sure whether this may slow down the algorithms or whether FxCop will be happy with those Lists. </p> <p>What is the best option to replace these <code>double[]</code> properties?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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