ArrayList Capacity property in C# – Programming Code Examples
C# C# Console Application

ArrayList Capacity property in C#1 min read

.Net framework ArrayList Capacity property allow us to get or set the number of elements that the ArrayList can contain. this arraylist Capacity property exists in System.Collections namespace.

arraylist Capacity property return value data type is System.Int32. this return integer value represents the number of elements that the ArrayList can contain.




arraylist Capacity property throw ArgumentOutOfRangeException exception, if ‘Capacity’is set to a value that is less than Count. this property also throw OutOfMemoryException exception, if there is not enough memory available on the system.

Capacity is the number of elements that the arraylist can store and Count is the number of elements that are actually exists in arraylist. Capacity is always greater than or equal to Count. Capacity is automatically increased by reallocating the internal array before adding new elements and copying the old elements.

the following console c# example code demonstrate us how can we get or set arraylist Capacity propgrammatically at run time in an console application.

C# Code:

Output:

 

Leave a Comment