ArrayLists are dynamic, i.e, it can grow to any size, by default. The following code shows how to fix the size of the Array List.
// Create an arraylist with initial capacity of 2 elements System.Collections.ArrayList al = new ArrayList(2);
// Now, fix the size.
al = System.Collections.ArrayList.FixedSize(al);
//Add two elements to the arraylist
al.Add("Bala"); al.Add("Murali");
// When you try to add another item, an exception is thrown. al.Add("Balaji");
|
No responses found. Be the first to respond and make money from revenue sharing program.
|