O'Reilly logo

C# 6.0 Cookbook, 4th Edition by Jay Hilyard, Stephen Teilhet

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 2. Collections, Enumerators, and Iterators

2.0 Introduction

Collections are groups of items; in .NET, collections contain objects, and each object contained in a collection is called an element. Some collections contain a straightforward list of elements, while others (dictionaries) contain a list of key/value pairs. The following collection types consist of a straightforward list of elements:

System.Collections.ArrayList
System.Collections.BitArray
System.Collections.Queue
System.Collections.Stack
System.Collections.Generic.LinkedList<T>
System.Collections.Generic.List<T>
System.Collections.Generic.Queue<T>
System.Collections.Generic.Stack<T>
System.Collections.Generic.HashSet<T>

The next set of collection types are all dictionaries:

System.Collections.Hashtable
System.Collections.SortedList
System.Collections.Generic.Dictionary<T,U>
System.Collections.Generic.SortedList<T,U>

This last collection type (HashSet<T>) can be thought of as a list of elements with no duplicates:

System.Collections.Generic.HashSet<T>

These collection classes are organized under the System.Collections and the System. Collections.Generic namespaces. In addition to these namespaces, there is a namespace called System.Collections.Specialized, which contains a few more useful collection classes. These classes might not be as well known as the previous classes, so here is a short explanation of them:

ListDictionary
This class operates similarly to the Hashtable. However, this class beats out ...

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