tags:

views:

94

answers:

3

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<>?

+10  A: 

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.

driis
+3  A: 

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

Dave Swersky
+6  A: 

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;
JaredPar