.NET 数组 - “Length"、“Count()"之间的区别和“排名" [英] .NET array - difference between "Length", "Count()" and "Rank"
问题描述
Length"、Count()"和Count()"有什么区别?和排名"对于 .NET 数组?
Length
是数组对象的属性,使用它是确定数组中元素个数的最有效方法(MSDN 文档中的Array.Length).>
Count()
是一个 LINQ 扩展方法有效相同.它适用于数组,因为数组是可枚举的对象.最好使用 Length
,因为 Count()
可能更贵(参见 这个问题 进一步讨论和Count 上的 MSDN 文档 供参考).
Rank
是返回维度数的属性(完全不同).当你声明一个数组int[,] myArray = new int[5,10];
时,它的Rank
会是2,但是总共会容纳50元素(MSDN on Rank 属性)..>
What's the difference between "Length", "Count()" and "Rank" for a .NET array?
Length
is the property of an array object and using it is the most effective way to determine the count of elements in the array (Array.Length in MSDN documentation).
Count()
is a LINQ extension method that does effectively the same. It applies to arrays because arrays are enumerable objects. It's preferred to use Length
, because Count()
is likely to be more expensive (see this question for further discussion and MSDN documentation on Count for reference).
Rank
is the property that returns the number of dimensions (a different thing entirely). When you declare an array int[,] myArray = new int[5,10];
, the Rank
of it will be 2, but it will hold a total of 50 elements (MSDN on Rank property).
这篇关于.NET 数组 - “Length"、“Count()"之间的区别和“排名"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!