Chapter 7. Collections
Collections are standard data structures that supplement arrays, which are the only built-in data structures in C#. 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 FCL includes a set of types that provide commonly required data structures and support for creating your own. These types are typically broken down into two categories: interfaces that define a standardized set of design patterns for collection classes in general, and concrete classes that implement these interfaces and provide a usable range of data structures.
This chapter introduces all the concrete collection classes and
abstract collection interfaces and provides examples of their use.
Unless otherwise stated, the types mentioned in this section all
exist in the System.Collections
or
System.Collections.Specialized
namespaces, which
are both documented in the reference section of this book, Part V.
Iterating Over Collections
In computing, there are many
different kinds of collections ranging from
simple data structures, such as arrays or linked lists, to more
complex ones, such as red/black trees and priority queues. While the
internal implementation and external characteristics of these data
structures vary widely, the ability to traverse the contents of the
collection is an almost universal need. In the FCL, this is supported
via a pair of interfaces (IEnumerable
and
IEnumerator ...
Get C# in a Nutshell, Second Edition 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.