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.
精彩评论