Collections Provided by the Base Class Libraries
Out of the box, C# contains several useful collections. Each of them is slightly different from the other and has its own advantages and disadvantages. This next section gives small examples of how to use each one.
Using an ArrayList
Like an array, an ArrayList is a collection that can be accessed through an index. Listing 5.5 demonstrates how to create, add items to, remove, and iterate through an ArrayList.
Listing 5.5. An ArrayList Example
using System; using System.Collections; namespace ArrayListCollection { class Class1 { static protected ArrayList list = new ArrayList(); protected static void PrintList(System.Collections.ArrayList list) { IEnumerator enumerator = list.GetEnumerator(); while(enumerator.MoveNext()) ... |
Get Microsoft® Visual C#® .NET 2003 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.