Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c#

list

asp.net

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

like image 683
locoboy Avatar asked Aug 22 '10 18:08

locoboy


People also ask

How do I find the size of a list?

To get the length of a list in Python, you can use the built-in len() function. Apart from the len() function, you can also use a for loop and the length_hint() function to get the length of a list. In this article, I will show you how to get the length of a list in 3 different ways.

How big can a list be in C#?

List size can be increased up to 2 billion (only when your system works on 64-bit or higher) to store large List<T> objects.

What is a list in C#?

Lists in C# are very similar to lists in Java. A list is an object which holds variables in a specific order. The type of variable that the list can store is defined using the generic syntax.


1 Answers

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;
like image 136
JaredPar Avatar answered Oct 23 '22 08:10

JaredPar