Skip to Main Content
C# in a Nutshell, Second Edition
book

C# in a Nutshell, Second Edition

by Peter Drayton, Ben Albahari, Ted Neward
August 2003
Intermediate to advanced content levelIntermediate to advanced
928 pages
32h 1m
English
O'Reilly Media, Inc.
Content preview from C# in a Nutshell, Second Edition

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

C# in a Nutshell

C# in a Nutshell

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

C# 7.0 in a Nutshell

Joseph Albahari, Ben Albahari
C# Cookbook, 2nd Edition

C# Cookbook, 2nd Edition

Jay Hilyard, Stephen Teilhet
C# Cookbook

C# Cookbook

Stephen Teilhet, Jay Hilyard

Publisher Resources

ISBN: 0596005261Catalog PageErrata