anildevkj
anildevkj

Reputation: 381

finding the maximum length of lists in c#

After I have created a list and added the contents to it, how can I find the length of the list?

Upvotes: 38

Views: 204298

Answers (6)

EDUARDO PICOLO XAVIER
EDUARDO PICOLO XAVIER

Reputation: 11

You look to property size, then property length. But in c# its Count

myList.ToArray().Length

Upvotes: 1

user2941743
user2941743

Reputation: 61

Example:

List<string> A = new List<string>();
int Length_A = A.Count;

Upvotes: 6

na_yan
na_yan

Reputation: 56

Example: Let we are creating a List with some string named vec. Then Add 3 string and see the size using vec.Count.

List<string> vec = new List<string>();      
vec.Add("Md.");        
vec.Add("Ahsan");          
vec.Add("Habib");           
Console.WriteLine(vec.Count);

Upvotes: 1

Fran Bonafina
Fran Bonafina

Reputation: 140

You look to property size, then property length. But in c# its Count

MSDN screenshot

Upvotes: 5

David Brown
David Brown

Reputation: 36239

List<T>.Count

Upvotes: 10

Andrew Hare
Andrew Hare

Reputation: 351526

Try this:

Int32 length = yourList.Count;

In C#, arrays have a Length property, anything implementing IList<T> (including List<T>) will have a Count property.

Upvotes: 60

Related Questions