Книга: C# 2008 Programmer

Generics and the .NET Framework Class Library

Generics and the .NET Framework Class Library

The .NET Framework class library contains a number of generic classes that enable users to create strongly typed collections. These classes are grouped under the System.Collections.Generic namespace (the nongeneric versions of the classes are contained within the System.Collections namespace). The following tables show the various classes, structures, and interfaces contained within this namespace.

The following table provides a look at the classes contained within the System.Collections.Generic namespace.

Class Description
Comparer<(Of <(T>)>) Provides a base class for implementations of the IComparer<(Of <(T>)>) generic interface.
Dictionary<(Of <(TKey, TValue>)>) Represents a collection of keys and values.
Dictionary<(Of <(TKey, TValue>)<)..::.KeyCollection Represents the collection of keys in a Dictionary<(Of <(TKey, TValue>)>). This class cannot be inherited.
Dictionary<(Of <(TKey, TValue>)>)..::.ValueCollection Represents the collection of values in a Dictionary<(Of <(TKey, TValue>)>). This class cannot be inherited.
EqualityComparer<(Of <(T>)>) Provides a base class for implementations of the IEqualityComparer<(Of <(T>)>) generic interface.
HashSet<(Of <(T>)>) Represents a set of values.
KeyedByTypeCollection<(Of <(TItem>)>) Provides a collection whose items are types that serve as keys.
KeyNotFoundException The exception that is thrown when the key specified for accessing an element in a collection does not match any key in the collection.
LinkedList<(Of <(T>)>) Represents a doubly linked list.
LinkedListNode<(Of <(T>)>) Represents a node in a LinkedList<(Of <(T>)>). This class cannot be inherited.
List<(Of <(T>)>) Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.
Queue<(Of <(T<)>) Represents a first-in, first-out collection of objects.
SortedDictionary<(Of <(TKey, TValue>)>) Represents a collection of key/value pairs that are sorted on the key.
SortedDictionary<(Of <(TKey, TValue>)>)..::.KeyCollection Represents the collection of keys in a SortedDictionary<(Of <(TKey, TValue>)>). This class cannot be inherited.
SortedDictionary<(Of <(TKey, TValue>)>)..::.ValueCollection Represents the collection of values in a SortedDictionary<(Of <(TKey, TValue>)>). This class cannot be inherited.
SortedList<(Of <(TKey, TValue>)>) Represents a collection of key/value pairs that are sorted by key based on the associated IComparer<(Of <(T>)>) implementation.
Stack<(Of <(T>)>) Represents a variable size last-in, first-out (LIFO) collection of instances of the same arbitrary type.
SynchronizedCollection<(Of <(T>)>) Provides a thread-safe collection that contains objects of a type specified by the generic parameter as elements.
SynchronizedKeyedCollection<(Of <(K, T>)>) Provides a thread-safe collection that contains objects of a type specified by a generic parameter and that are grouped by keys.
SynchronizedReadOnlyCollection <(Of <(T>)>) Provides a thread-safe, read-only collection that contains objects of a type specified by the generic parameter as elements.

The structures contained within the System.Collections.Generic namespace are described in the following table.

Structure Description
Dictionary<(Of <(TKey, TValue>)>)..::.Enumerator Enumerates the elements of a Dictionary<(Of <(TKey, TValue>)>)
Dictionary<(Of <(TKey, TValue>)>)..::. KeyCollection..::.Enumerator Enumerates the elements of a Dictionary<(Of <(TKey, TValue>)>)..::.KeyCollection
Dictionary<(Of <(TKey, TValue>)>)..::. ValueCollection..::.Enumerator Enumerates the elements of a Dictionary<(Of <(TKey, TValue>)>)..::.ValueCollection
HashSet<(Of <(T>)>)..::.Enumerator Enumerates the elements of a HashSet<(Of <(T>)>) object
KeyValuePair<(Of <(TKey, TValue>)>) Defines a key/value pair that can be set or retrieved
LinkedList<(Of <(T>)>)..::.Enumerator Enumerates the elements of a LinkedList<(Of <(T>)>)
List<(Of <(T>)>)..::.Enumerator Enumerates the elements of a List<(Of <(T>)>)
Queue<(Of <(T>)>)..::.Enumerator Enumerates the elements of a Queue<(Of <(T>)>)
SortedDictionary<(Of <(TKey, TValue>)>)..::.Enumerator Enumerates the elements of a SortedDictionary<(Of <(TKey, TValue>)>)
SortedDictionary<(Of <(TKey, TValue>)>)..::.KeyCollection..::.Enumerator Enumerates the elements of a SortedDictionary<(Of <(TKey, TValue>)>)..::.KeyCollection
SortedDictionary<(Of <(TKey, TValue>)>)..::.ValueCollection..::. Enumerator Enumerates the elements of a SortedDictionary<(Of <(TKey, TValue>)>)..::.ValueCollection
Stack(<Of <(T>)>)..::.Enumerator Enumerates the elements of a Stack<(Of <(T>)>)

Following are descriptions of the interfaces contained within the System.Collections.Generic namespace.

Interface Description
ICollection<(Of <(T>)>) Defines methods to manipulate generic collections
IComparer<(Of <(T>)>) Defines a method that a type implements to compare two objects
IDictionary<(Of <(TKey, TValue>)>) Represents a generic collection of key/value pairs
IEnumerable<(Of <(T>)>) Exposes the enumerator, which supports a simple iteration over a collection of a specified type
IEnumerator<(Of <(T>)>) Supports a simple iteration over a generic collection
IEqualityComparer<(Of <(T>)>) Defines methods to support the comparison of objects for equality
Ilist<(Of <(T>)>) Represents a collection of objects that can be individually accessed by index

Prior to .NET 2.0, all the data structures contained in the System.Collection namespace are object-based. With .NET 2.0, Microsoft has released generic equivalents of some of these classes. The following table shows the mapping of these classes in the two namespaces.

System.Collection System.Collection.Generic
Comparer Comparer<T>
HashTable Dictionary<K,T>
LinkedList<T>
ArrayList List<T>
Queue Queue<T>
SortedList SortedDictionary<K,T>
Stack Stack<T>
ICollection ICollection<T>
System.IComparable IComparable<T>
IDictionary IDictionary<K,T>
IEnumerable IEnumerable<T>
IEnumerator IEnumerator<T>
IList IList<T>

The Stack<T>, Queue<T>, and Dictionary<K,T> generic classes are discussed in more detail in Chapter 13, "Collections."

Оглавление книги


Генерация: 1.110. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз