C#中List的大小属性是什么?

loc*_*boy 6 c# asp.net list

如何在c#中访问List <>的大小?在数组中,它是array.length,但List <>的属性是什么?

dri*_*iis 13

它是List 的Count属性,几乎是Framework中的任何其他集合类.Count属性也在ICollection <T>接口上定义.


Jar*_*Par 13

如果您想知道列表中有多少元素,请使用Count属性.

int numElements = list.Count;
Run Code Online (Sandbox Code Playgroud)

另一方面,如果您想知道List<T>当前可以处理的后备存储的元素数量,那么请使用Capacity属性.

int size = list.Capacity;
Run Code Online (Sandbox Code Playgroud)


Dav*_*sky 5

Count 属性将为您提供列表中对象的数量。