ArrayList is stretchable. You can append, remove, or insert item easier than a normal array.
ArrayList stores items of object type. Although you add numbers or string values, they will be converted automatically to object type before storing them. You can convert object items back to string type by using toString() method.
How to convert them back to numbers?
Answer: apply int.parse() or int32.parse() method to the items of string type.
static void Main(string args)
ArrayList ls = new ArrayList();
ls.Capacity = 10;//set number of elements that arraylist can store
//add items to arraylist
ls.Insert(2,80); //insert item to a specific location
ls.Sort();//sort arrarylist in ascending order if you wan to sort the arraylist in descending order
//use reverse method after using sort method
//read items from arraylist
//reverse the arraylist to sort it in descedning order
for(i=0;i<ls.Count ;i++) //get number of arraylist elements by Count property
//use removeat(index) method to remove a specific item
//remove all items of the arraylist with clear method
//wait for key press
Posted by: Dara | post date: 01-25-2013 | Subject: C# Programming Language
This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages: