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?

6 Answers

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.

Example:

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

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

MSDN screenshot

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

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

myList.ToArray().Length

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Marcus Vance

Marcus Vance

Cybersecurity & Digital Privacy Researcher

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.

Share this article
Twitter Facebook Pinterest