C# | Capacity of a List Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report List<T>.Capacity Property is used to gets or sets the total number of elements the internal data structure can hold without resizing. Properties of List: It is different from the arrays. A list can be resized dynamically but arrays cannot. 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. Capacity Vs Count: Count is always less than the Capacity. While adding the elements, if Count exceeds Capacity then the Capacity will increase automatically by reallocating the internal array before copying the old elements and adding the new elements. Capacity is the number of the elements which the List can store before resizing of List needed. But Count is the number of the elements which are actually present in the List. If the Capacity is much larger than the Count the user can decrease capacity by either calling the TrimExcess method or explicitly setting the Capacity to a lower value. If the Capacity is settled explicitly then the internal array is also reallocated to accommodate the specified capacity, and all the elements are copied. Retrieving the value of Capacity property is an O(1) operation while setting the Capacity is an O(n) operation, where n is the new capacity. Syntax: public int Capacity { get; set; } Return Value: This method returns the number of elements that the List<T> can contain before resizing is required of type System.Int32. Exceptions: ArgumentOutOfRangeException : If the capacity is set to a value that is less than Count. OutOfMemoryException : If there is not enough memory available on the system. Below programs illustrate the use of Capacity Property: Example 1: CSharp // C# program to illustrate the // Capacity Property of List<T> using System; using System.Collections.Generic; class Geeks { // Main Method public static void Main(String[] args) { // Creating a List of integers // Here we are not setting // Capacity explicitly List<int> firstlist = new List<int>(); // adding elements in firstlist firstlist.Add(1); firstlist.Add(2); firstlist.Add(3); firstlist.Add(4); // Printing the Capacity of firstlist Console.WriteLine("Capacity Is: " + firstlist.Capacity); // Printing the Count of firstlist Console.WriteLine("Count Is: " + firstlist.Count); // Adding some more // elements in firstlist firstlist.Add(5); firstlist.Add(6); // Printing the Capacity of firstlist // It will give output 8 as internally // List is resized Console.WriteLine("Capacity Is: " + firstlist.Capacity); // Printing the Count of firstlist Console.WriteLine("Count Is: " + firstlist.Count); } } Output: Capacity Is: 4 Count Is: 4 Capacity Is: 8 Count Is: 6 Example 2: CSharp // C# program to illustrate the // Capacity Property of List<T> using System; using System.Collections.Generic; class Geeks { // Main Method public static void Main(String[] args) { // Creating a List of integers // Here we are setting Capacity // explicitly i.e. List<int> firstlist = new List<int>(10); // Printing the Capacity of firstlist Console.WriteLine("Capacity Is: " + firstlist.Capacity); // Printing the Count of firstlist Console.WriteLine("Count Is: " + firstlist.Count); // adding elements in firstlist firstlist.Add(1); firstlist.Add(2); firstlist.Add(3); firstlist.Add(4); // Printing the Capacity of firstlist Console.WriteLine("Capacity Is: " + firstlist.Capacity); // Printing the Count of firstlist Console.WriteLine("Count Is: " + firstlist.Count); // Adding some more // elements in firstlist firstlist.Add(5); firstlist.Add(6); // Printing the Capacity of firstlist // It will give output 10 as we have // already set the Capacity Console.WriteLine("Capacity Is: " + firstlist.Capacity); // Printing the Count of firstlist Console.WriteLine("Count Is: " + firstlist.Count); } } Output: Capacity Is: 10 Count Is: 0 Capacity Is: 10 Count Is: 4 Capacity Is: 10 Count Is: 6 Reference: https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.capacity?view=netframework-4.7.2 Comment More infoAdvertise with us Next Article C# | How to create a Stack K Kirti_Mangal Follow Improve Article Tags : C# CSharp-Generic-List CSharp-Collections-Namespace CSharp-Generic-Namespace Similar Reads C# | Capacity of a SortedList SortedList.Capacity Property is used to get or set the capacity of a SortedList object. Syntax: public virtual int Capacity { get; set; } Return Value: This property returns the number of elements of type System.Int32 that the SortedList object can contain. Exceptions: ArgumentOutOfRangeException: I 3 min read C# List Class In C#, the List<T> class represents the list of objects that can be accessed by index. It comes under the System.Collections.Generic namespace. List class can be used to create a collection of different types like integers, strings, etc. List<T> class also provides the methods to search, 7 min read C# | How to create a Stack Stack() constructor is used to initialize a new instance of the Stack class which will be empty and will have the default initial capacity. Stack represents a last-in, first out collection of object. It is used when you need last-in, first-out access to items. When you add an item in the list, it is 2 min read C# List Implementation In C#, a List is a generic collection used to store the elements or objects in the form of a list defined under System.Collection.Generic namespace. It provides the same functionality as ArrayList, the difference is a list is generic whereas ArrayList is a non-generic collection. It is dynamic means 7 min read C# | Adding an element to the List List.Add(T) Method is used to add an object to the end of the List. Properties of List: It is different from the arrays. A list can be resized dynamically but arrays cannot. List class can accept null as a valid value for reference types and it also allows duplicate elements. If the Count becomes eq 2 min read How to create the ArrayList in C# ArrayList() constructor is used to initialize a new instance of the ArrayList class which will be empty and will have the default initial capacity. ArrayList represents an ordered collection of an object that can be indexed individually. It is basically an alternative to an array. It also allows dyn 2 min read Like