C sharp arraylist are particularly useful in:

C sharp arraylist is different from list as data structure in good old fashion C. List is a data structure where nodes can’t be accessed by index, but by pointer only. C sharp arraylist can be accessed either by pointer or by index. The only difference between array and arraylist in C sharp is that arraylist resizes online, while size of an array must be defined in advance. And one thing more: array as data type in C# goes automatically, while for using arraylist namespace System.Collections must be included. Here is one C sharp arraylist example:

using System.Collections;

static void Main(string[] args)

ArrayList alMonth = new ArrayList();

All arraylist Members can be displayed with foreach loop:

foreach (Object obj in alMonth)

Console.WriteLine(“{0}“, obj);


Now, missed month “February” can be inserted to the right place by:

alMonth.Insert(1, “February”);

Note: first element in arraylist is indexed with zero.

Element in arraylist can be deleted with

Elements also can be deleted in certain range:
alMonth.RemoveRange(1, 3);

And all arraylist can be cleared as well:

Arraylist can be sorted in regular order:

or in reverse order:

Two arraylists can be joined together:

ArrayList alDay = new ArrayList();

Arraylist can also be counted and displayed in classic for loop if we online count arraylist elements:

for (int int_i = 0; int_i < alMonth.Count; int_i++)

string str_display = alMonth[int_i] as string;


Arraylist in C# are used in situations where list were used in C, (binary trees and other list tasks), and also as invisible structure that supports ListBox control, as it will be discussed later.

External links:

C Sharp Arraylist Example on csharp.net-informations.com
C Sharp Arraylist Example on Microsoft
C Sharp Arraylist Example on C-sharpcorner.com
C Sharp Arraylist Example on Dotnetperls

Posted in c-sharp-code-examples

Leave a Reply

Your email address will not be published. Required fields are marked *