O'Reilly logo

C# in a Nutshell by Peter Drayton, Ted Neward, Ben Albahari

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Predefined Collection Classes

The FCL provides a reasonably comprehensive set of prebuilt data structures providing concrete implementations of all the interfaces described in this chapter. However, since C# does not yet support generics, the implementations work in terms of the generic object type, which has the same disadvantages (excessive casting, boxing) as the generic IEnumerator interface described earlier. If you prefer more type-safe collection classes, you may use one of these predefined types as a starting point for your own type-safe variant.

The Array Class

The Array class is the canonical aggregate data structure in the FCL, representing a fixed-size array of object references of uniform type. Since the Array data structure is fundamental, the C# language provides explicit array declaration and initialization syntax (for more details, see Chapter 2 and Chapter 3). The storage for the array is allocated on the GC heap at the time a class is instantiated, and cannot change (see the ArrayList class for a growable array-like data structure). The Array class implements ICollection, IList, and IEnumerable, so arrays can be treated as lists, generic cloneable collections, or sets of elements that can be enumerated. In addition, the Array class supports sorting and searching of the array. Sorting of the array is often accomplished by delegating to IComparable implementations on the contained elements, which requires that you implement IComparable on types that are intended for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required