.net array - difference between “Length”, “Count()” and “Rank”

前端 未结 6 2302
时光说笑
时光说笑 2020-12-15 15:19

What\'s the difference between \"Length\", \"Count()\" and \"Rank\" for .net array?

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-15 16:07

    Length is a property of Array since C# 1.x

    Count()is an extension method of IEnumerable, because now every T[] implements IEnumerable implicitly.

    Note that for an array, Count() is usually much slower than Length, because accessing Length property is O(1), while Count is for IEnumerable, so the program needs to go through the collection and get its count, that is O(n).

    Rank gives the demensions of the array.

提交回复
热议问题