开发者

what is the property for the size of a List in C#?

How do you access the size of a List<> 开发者_开发技巧in c#? In an array it's array.length, but what is the property for a List<>?


If you want to know how many elements are in the list then use the Count property.

int numElements = list.Count;

On the other hand if you want to know how many elements the backing storage of the List<T> can currently handle then then use the Capacity property.

int size = list.Capacity;


It is the Count property for List, and in almost any other collection class in the Framework. The Count property is also defined on the ICollection<T> interface.


The Count property will give you the number of objects in the list.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜