Archive

Posts Tagged ‘System.Collections.Generic.Arraylist’

ArrayList in C#

July 22, 2015 Leave a comment

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
%d bloggers like this: