Chapter 10. Collections

WHAT'S IN THIS CHAPTER?

  • Understanding collection interfaces and types

  • Working with lists, queues, and stacks

  • Working with linked and sorted lists

  • Using dictionaries and sets

  • Using bit arrays and bit vectors

  • Evaluating performance

In Chapter 6, "Arrays and Tuples," you read about arrays and the interfaces implemented by the Array class. The size of arrays is fixed. If the number of elements is dynamic, you should use a collection class.

List<T> is a collection class that can be compared to arrays. But there are also other kinds of collections: queues, stacks, linked lists, and dictionaries.

Note

Version 1 of the .NET Framework included non-generic collection classes such as ArrayList and HashTable. CLR 2.0 added support for generics and generic collection classes. The focus of this chapter is on the newer group of collection classes and mainly ignores the old ones, as they are rarely needed with new applications.

COLLECTION INTERFACES AND TYPES

Most collection classes can be found in the System.Collections and System.Collections.Generic namespaces. Generic collection classes are located in the System.Collections.Generic namespace. Collection classes that are specialized for a specific type are located in the System.Collections.Specialized namespace. Thread-safe collection classes are in the System.Collections.Concurrent namespace.

Of course, there are also other ways to group collection classes. Collections can be grouped into lists, collections, and dictionaries based ...

Get Professional C# 4 and .NET 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.