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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access