Adding
Initailising ArrayLists
The default capacity for a new arraylist is 16 elements.
System.Collections.ArrayList myArrayList;
myArrayList = new System.Collections.ArrayList();
Accessing Elements - Zero Based
Items can be returned using an index that starts at zero.
System.Collections.ArrayList myArrayList;
myArrayList = new System.Collections.ArrayList();
myArrayList.Add("string");
myArrayList.Add(20);
myArrayList.Add(false);
Console.WriteLine(myArrayList[1]);
Capacity
You should always try and define an initial capacity for your arraylist if possible.
You can modify the capacity at any time by assigning a value to the Capacity property
myArrayList.Capacity = myArrayList.Count
Another way to achieve the same result is to use the TrimToSize property
myArrayList.TrimToSize
When the current capacity is exceeded the ArrayList will automatically double its capacity.
Inserting
Insert - Inserts an element at the specified index.
InsertRange -
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext