Commonly Used Collection Types
Collection types are the common variations of data collections, such as hash tables, queues, stacks, dictionaries, and lists.
Collections are based on the ICollection interface, the IList interface, the IDictionary interface, or their generic counterparts. The IList interface and the IDictionary interface are both derived from the ICollection interface; therefore, all collections are based on the ICollection interface either directly or indirectly. In collections based on the IList interface (such as Array, ArrayList, or List<T>) or directly on the ICollection interface (such as Queue, Stack, or LinkedList<T>), every element contains only a value. In collections based on the IDictionary interface (such as the Hashtable and SortedList classes, or the Dictionary<TKey, TValue> and SortedList<TKey, TValue> generic classes), every element contains both a key and a value. The KeyedCollection<TKey, TItem> class is unique because it is a list of values with keys embedded within the values and, therefore, it behaves like a list and like a dictionary.
Generic collections are the best solution to strong typing. However, if your language does not support generics, the System.Collections namespace includes base collections, such as CollectionBase, ReadOnlyCollectionBase, and DictionaryBase, which are abstract base classes that can be extended to create collection classes that are strongly typed.
Collections can vary, depending on how the elements are stored, how they are sorted, how searches are performed, and how comparisons are made. The Queue class and the Queue<T> generic class provide first-in-first-out lists, while the Stack class and the Stack<T> generic class provide last-in-first-out lists. The SortedList class and the SortedList<TKey, TValue> generic class provide sorted versions of the Hashtable class and the Dictionary<TKey, TValue> generic class. The elements of a Hashtable or a Dictionary<TKey, TValue> are accessible only by the key of the element, but the elements of a SortedList or a KeyedCollection<TKey, TItem> are accessible either by the key or by the index of the element. The indexes in all collections are zero-based, except Array, which allows arrays that are not zero-based.
The LINQ to Objects feature allows you to use LINQ queries to access in-memory objects as long as the object type implements IEnumerable or IEnumerable<T>. LINQ queries provide a common pattern for accessing data; are typically more concise and readable than standard foreach loops; and provide filtering, ordering and grouping capabilities. LINQ queries can also improve performance. For more information, see LINQ to Objects.
In This Section
Array Collection Type
Describes the features of arrays that allow them to be treated like collections.ArrayList and List Collection Types
Describes the features of generic and nongeneric lists, the most commonly used collection types.Hashtable and Dictionary Collection Types
Describes the features of generic and nongeneric hash-based dictionary types.SortedList and SortedDictionary Collection Types
Describes the sorted dictionary and the hybrid types that combine dictionary and list functionality.Queue Collection Types
Describes the features of generic and nongeneric queues.Stack Collection Types
Describes the features of generic and nongeneric stacks.HashSet Collection Type
Describes the generic HashSet<T> collection type.HashSet and LINQ Set Operations
Describes set operations provided by the HashSet<T> collection type and LINQ Set operations.
Reference
System.Collections
Provides reference documentation for the System.Collections namespace, which contains interfaces and classes that define various collections of objects.System.Collections.Generic
Provides reference documentation for the System.Collections.Generic namespace, which contains interfaces and classes that define generic collections.System.Collections.ICollection
Describes the major features of the ICollection class, which defines size, enumerators and synchronization methods for all nongeneric collections.System.Collections.Generic.ICollection<T>
Describes the major features of the ICollection<T> class, which defines methods to manipulate generic collections.System.Collections.IList
Describes the major features of the IList class, which represents a nongeneric collection of objects that can be individually accessed by index.System.Collections.Generic.IList<T>
Describes the major features of the IList<T> class, which represents a collection of objects that can be individually accessed by index.System.Collections.IDictionary
Describes the major features of the IDictionary class, which represents a nongeneric collection of key/value pairs.System.Collections.Generic.IDictionary<TKey, TValue>
Describes the major features of the IDictionary<TKey, TValue> class, which represents a generic collection of key/value pairs.
Related Sections
Collections and Data Structures
Discusses the various collection types available in the .NET Framework, including stacks, queues, lists, arrays, and structs.Generics in the .NET Framework
Describes the generics feature, including the generic collections, delegates, and interfaces provided by the .NET Framework. Provides links to feature documentation for C#, Visual Basic, and Visual C++, and to supporting technologies such as reflection.