Home > C# > ArrayList in C#

ArrayList in C#

Benefits of Array List

  1. Insert Elements: An Array List starts with a collection containing no elements. You can add them in any position as you choose them.
  2. Automatic Resizing: you do not need to specify the array size; as you add elements, the array automatically ensures there is enough memory for the array.
  3. Flexibility When Removing Elements: you can remove any element from an Array list very easily.

Limitations of Array List

The flexibility of Array List comes at a cost of performance. Since memory allocation is a very expensive business, the fixed number of elements of the simple array
makes it much faster to work with.

Example:

ArrayList obj = new ArrayList();
obj.Add(“item1”);
obj.Add(“2”);
obj.Add(“Delhi”);

Obj.Insert(2,”item2″);

Obj.Remove(“item1”);
Obj.RemoveAt(3);

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: