In some scenarios, we need to get the count of elements in a list in C# or the length of a list in C#.

These are the cases where we need to check if the length or the number of elements in the list is greater than or less than some number.

The .Count property gets the number of elements contained in the System.Collections.Generic.List

Using the count method, we are able to easily get the number of elements in a collection in C# or the length of list in C#.

 

 

Get Count Of Elements In List C#

Let's see the use of the .Count property in an actual example.

var listOfColors = new List { "red", "orange", "green", "blue" }; // Get Length of list C# // or // Get Count Of Elements In List C# int count = listOfColors.Count; // Display The Count Of Elements In The List Console.WriteLine(count);

 

Result:

4