Reputation: 381
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
Reputation: 11
You look to property size, then property length. But in c# its Count
myList.ToArray().Length
Upvotes: 1
Reputation: 61
Example:
List<string> A = new List<string>();
int Length_A = A.Count;
Upvotes: 6
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
Reputation: 140
You look to property size
, then property length
. But in c#
its Count
Upvotes: 5
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