Count property vs Count() method?

后端 未结 8 2233
孤街浪徒
孤街浪徒 2020-11-27 04:21

Working with a collection I have the two ways of getting the count of objects; Count (the property) and Count() (the method). Does anyone know what

8条回答
  •  囚心锁ツ
    2020-11-27 05:01

    Count() is there as an extension method from LINQ - Count is a property on Lists, actual .NET collection objects.

    As such, Count() will almost always be slower, since it will enumerate the collection / queryable object. On a list, queue, stack etc, use Count. Or for an array - Length.

提交回复
热议问题