C# | Count the total number of elements in the List Last Updated : 01 Feb, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report List class represents the list of objects which can be accessed by index. It comes under the System.Collection.Generic namespace. List class can be used to create a collection of different types like integers, strings etc. List class also provides the methods to search, sort, and manipulate lists. List.Count Property is used to get the total number of elements contained in the List. Properties: It is different from the arrays. A list can be resized dynamically but arrays cannot be. List class can accept null as a valid value for reference types and it also allows duplicate elements. If the Count becomes equals to Capacity then the capacity of the List increases automatically by reallocating the internal array. The existing elements will be copied to the new array before the addition of the new element. Syntax: list_name.Count Below programs illustrate the use of Count property: Example 1: CSharp // C# code to get the number of // elements contained in List using System; using System.Collections.Generic; class Geeks { // Main Method public static void Main() { // Creating a List of integers List<int> firstlist = new List<int>(); // adding elements in firstlist for (int i = 4; i < 10; i++) { firstlist.Add(i * 2); } // To get the number of // elements in the List Console.WriteLine(firstlist.Count); } } Output: 6 Example 2: CSharp // C# code to get the number of // elements contained in List using System; using System.Collections.Generic; class Geeks { // Main Method public static void Main() { // Creating a List of integers List<int> firstlist = new List<int>(); // To get the number of // elements in the List Console.WriteLine(firstlist.Count); } } Output: 0 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.count?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | Count the total number of elements in the List K Kirti_Mangal Follow Improve Article Tags : C# CSharp-Generic-List CSharp-Collections-Namespace CSharp-Generic-Namespace Similar Reads C# | Get the number of elements contained in the Stack Stack represents a last-in, first out collection of object. Stack<T>.Count Property is used to gets the number of elements contained in the Stack. Retrieving the value of this property is an O(1) operation. Syntax: myStack.Count Here myStack is the name of the Stack<T> Return Value: The 2 min read Count the number of element present in the sequence in LINQ? In LINQ, you can count the total number of elements present in the given sequence by using the Count Method. This method returns the total number of elements present in the given sequence. This method can be overloaded in two different ways: Count<TSource>(): This method returns the total numb 3 min read C# | Get the number of elements contained in SortedList SortedList.Count Property is used to get the number of elements contained in a SortedList object. Syntax: public virtual int Count { get; } Property Value: The number of elements contained in the SortedList object. Below programs illustrate the use of above discussed method: Example 1: CSharp // C# 2 min read C# | Total number of elements present in an array Array.GetLength(Int32) Method is used to find the total number of elements present in the specified dimension of the Array. Syntax: public int GetLength (int dimension); Here, dimension is a zero-based dimension of the Array whose length needs to be determined.Return value: The return type of this m 2 min read C# | Get the number of elements in the SortedSet SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. SortedSet<T>.Count Property is used to get the number of elements in the SortedSet. Properties: In C#, SortedSet class can be used to store, remove or view elemen 2 min read Like