Electronic and Electric Circuit Simulation
Home C Sharp Code Examples c sharp arraylist example
c sharp arraylist example PDF Print E-mail


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.

<< Previous reading Next reading>>

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

Copyright © 2015 Electronic and Electric Circuit Simulation. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License. Top joomla 1.5 themes
Top joomla 1.5 themes designed by Lonex.

Recent/Mostly Visited

Simulate recent1: IDFT Reconstruction

Simulate recent2: DFT Coefficients Calculator

Simulate recent3: Op-Amp Summing Amplifier