O'Reilly logo

C# 3.0 in a Nutshell, 3rd Edition by Ben Albahari, Joseph 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

Chapter 7. Collections

The .NET Framework provides a standard set of types for storing and managing collections of objects. These include resizable lists, linked lists, sorted and unsorted dictionaries as well as arrays. Of these, only arrays form part of the C# language; the remaining collections are just classes you instantiate like any other. In this, C# differs from languages such as Perl and Python, which incorporate key/value data structures and dynamically sized arrays into the language itself.

The types in the Framework for collections can be divided into the following categories:

  • Interfaces that define standard collection protocols

  • Ready-to-use collection classes (lists, dictionaries, etc.)

  • Base classes for writing application-specific collections

This chapter covers each of these categories, with an additional section on the types used in determining equality and order within collections. Where applicable, both generic and nongeneric versions of each collection type are described, with less emphasis on older Framework types in cases when they've been largely superseded. Table 7-1 lists collection namespaces.

Table 7-1. Collection namespaces

Namespace

Contains

System.Collections

Nongeneric collection classes and interfaces

System.Collections.Specialized

Strongly typed nongeneric collection classes

System.Collections.Generic

Generic collection classes and interfaces

System.Collections.ObjectModel

Proxies and bases for custom collections

Enumeration

computing, there are many different kinds ...

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