System.Collections

Many general-purpose collections are implemented in the .NET Framework SDK. Most of these collections are used as base classes to customize the feature set for an application.

System.Collections.ArrayList

Unlike the Array, an ArrayList can dynamically change its size as new items are added to the collection. Listing B.19 shows an example using an ArrayList (arraylist.cs).

Listing B.19. ArrayList Example
 static void Main(string [] args) { ArrayList al = new ArrayList(); lock(al.SyncRoot) { al.Add("This"); al.Add("is"); al.Add("a"); al.Add("test"); al.Add(0); al.Add(1); Console.WriteLine("Sychronized: {0} ", al.IsSynchronized); Console.WriteLine("Read-only: {0} ", al.IsReadOnly); Console.WriteLine("Fixed size: {0} ", al.IsFixedSize); ...

Get .NET Common Language Runtime 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.