How to use C# ArrayList Class
ArrayList is one of the most flexible data structure from CSharp Collections. ArrayList contains a simple list of values. ArrayList implements the IList interface using an array and very easily we can add , insert , delete , view etc. It is very flexible because we can add without any size information , that is it will grow dynamically and also shrink .
Add : Add an Item in an ArrayList Insert : Insert an Item in a specified position in an ArrayList Remove : Remove an Item from ArrayList RemoveAt: remove an item from a specified position
Sort : Sort Items in an ArrayList
How to add an Item in an ArrayList ?
Syntax : ArrayList.add(object) object : The Item to be add the ArrayList ArrayList arr;
How to Insert an Item in an ArrayList ?
Syntax : ArrayList.insert(index,object) index : The position of the item in an ArrayList object : The Item to be add the ArrayList ArrayList arr;
How to remove an item from arrayList ?
Syntax : ArrayList.Remove(object) object : The Item to be add the ArrayList
How to remove an item in a specified position from an ArrayList ?
Syntax : ArrayList.RemoveAt(index) index : the position of an item to remove from an ArrayList
How to sort ArrayList ?
Syntax : ArrayList.Sort()
The following CSharp source code shows some function in ArrayList
When you execute this C# program , at first add five items in the arraylist and displays. Then again one more item inserted in the third position , and then sort all items. Next it remove the item1 and also remove the item in the third position . Finally it shows the existing items.