Namespace: System.Collections.Generic
.Net Framework provides support for creating general purpose
classes/interfaces/delegates which can be consumed by any data type. The data
type is specified as generic parameter while creating the respective object.
Generic Collection class structure:
Similar
to non-generic collections generic collections have generic interfaces. Like:
IEnumerator<T> →
IEnumerable<T> →
ICollection<T> →
IList<T>
Similarly to have typed enumerator one must use the typed
object to obtain typed enumerator:
List<string>.Enumertor e =
stringList.GetEnumerator();
Generic Collections also provide generic IComarer and IEqualityComparer
interface. But generics also provide default implementation as Comparer and EqualityComparer for IComparer
and IEqualityComparer respectively.
.Net Framework also provides CollectionBase,
ReadOnlyCollectionBase, and DictionaryBase classes to implement your own
collection base on them instead of looking for interfaces and implementing
them.
Comments