How to create the ArrayList in C# Last Updated : 18 Feb, 2019 Comments Improve Suggest changes Like Article Like Report 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 dynamic memory allocation, adding, searching and sorting items in the list. Syntax: public ArrayList (); Important Points: The number of elements that an ArrayList can hold is known as the Capacity of the ArrayList. If the elements will be added to the ArrayList then capacity will be automatically increased by reallocating the internal array. Specifying the initial capacity will eliminate the requirement to perform a number of resizing operations while adding elements to the ArrayList if the size of the collection can be estimated. This constructor is an O(1) operation. Example 1: csharp // C# Program to illustrate how // to create a ArrayList using System; using System.Collections; class Geeks { // Main Method public static void Main(String[] args) { // arrlist is the ArrayList object // ArrayList() is the constructor // used to initializes a new // instance of the ArrayList class ArrayList arrlist = new ArrayList(); // Count property is used to get the // number of elements in ArrayList // It will give 0 as no elements // are present currently Console.WriteLine(arrlist.Count); } } Output: 0 Example 2: csharp // C# Program to illustrate how // to create a ArrayList using System; using System.Collections; class Geeks { // Main Method public static void Main(String[] args) { // arrlist is the ArrayList object // ArrayList() is the constructor // used to initializes a new // instance of the ArrayList class ArrayList arrlist = new ArrayList(); Console.Write("Before Add Method: "); // Count property is used to get the // number of elements in ArrayList // It will give 0 as no elements // are present currently Console.WriteLine(arrlist.Count); // Adding the elements // to the ArrayList arrlist.Add("This"); arrlist.Add("is"); arrlist.Add("C#"); arrlist.Add("ArrayList"); Console.Write("After Add Method: "); // Count property is used to get the // number of elements in arrlist Console.WriteLine(arrlist.Count); } } Output: Before Add Method: 0 After Add Method: 4 Reference: https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist.-ctor?view=netframework-4.7.2#System_Collections_ArrayList__ctor Comment More infoAdvertise with us Next Article How to create the ArrayList in C# K Kirti_Mangal Follow Improve Article Tags : C# CSharp-Collections-Namespace CSharp-Collections-ArrayList Similar Reads How to create a shallow copy of ArrayList in C# ArrayList.Clone() Method is used to create a shallow copy of the specified ArrayList. A shallow copy of a collection copies only the elements of the collection irrespective of reference types or value types. But it does not copy the objects that the references refer to. The references in the new col 3 min read C# | How to convert an ArrayList to Array In C#, an array is a group of like-typed variables that are referred to by a common name. And each data item is called an element of the array. The data types of the elements may be any valid data type like char, int, float etc. and the elements are stored in a contiguous location.ArrayList represen 4 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# | How to create a SortedSet SortedSet class represents the collection of objects in sorted order. This class comes under the System.Collections.Generic namespace. Properties : In C#, SortedSet class can be used to store, remove or view elements. It maintains ascending order and does not store duplicate elements. It is suggeste 2 min read C# | How to create a SortedList SortedList class is a collection of (key, value) pairs which are sorted according to keys. Those pairs can be accessible by key and as well as by index(zero-based indexing). This comes under System.Collections namespace. Properties of SortedList: Internally the object of SortedList maintains two arr 2 min read Like