10Collections

OVERVIEW

Chapter 7, “Arrays,” covers 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 instead of an array.

List<T> is a collection class that can be compared to arrays; but there are also other kinds of collections: queues, stacks, linked lists, dictionaries, and sets. The other collection classes have partly different APIs to access the elements in the collection and often a different internal structure for how the items are stored in memory. This chapter covers these collection classes and their differences, including performance differences.

COLLECTION INTERFACES AND TYPES

Most collection classes are in the System.Collections and System.Collections.Generic namespaces. Generic collection classes are located in the

Get Professional C# 7 and .NET Core 2.0, 7th 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.