.NET Development Foundation/Using generic collections

System types and collections: Using generic collections

Using generic collections
Exam objective: Improve type safety and application performance in a .NET Framework application by using generic collections.

(Refer System.Collections.Generic namespace MSDN)

Collection.Generic interfaces

 * Generic IComparable interface - MSDN


 * Note that IComparable is a member of the System namespace.


 * You use this interface when you create a class and you want it to be used with generic types that support ordering (ex. SortedList or List.Sort) without having to specify a comparer object. The only method of IComparable is CompareTo(T other). There is an example on MSDN.


 * The following example implements IComparable for a custom made Point class. The example uses a List instead of a SortedList or OrderedDictionnary because the comparaison is done based on the distance of the points from the origin which can give the same value for many points.


 * Generic ICollection interface and Generic IList interface


 * Generic ICollection interface - MSDN


 * Generic IList interface - MSDN


 * Generic IComparer interface and Generic IEqualityComparer interface


 * Generic IComparer interface - MSDN


 * Generic IEqualityComparer interface - MSDN


 * Generic IDictionary interface - MSDN


 * Generic IEnumerable interface and Generic IEnumerator interface


 * Generic IEnumerable interface - MSDN


 * see also ONDotnet


 * Generic IEnumerator interface - MSDN


 * IHashCodeProvider interface - MSDN - Interface is now obsolete (as of .NET 2.0)

Generic Dictionary

 * Generic Dictionary class and Generic Dictionary.Enumerator structure


 * Generic Dictionary class - MSDN


 * Generic Dictionary.Enumerator structure - MSDN


 * Generic Dictionary.KeyCollection class and Dictionary.KeyCollection.Enumerator structure


 * Generic Dictionary.KeyCollection class - MSDN


 * Dictionary.KeyCollection.Enumerator structure - MSDN


 * Generic Dictionary.ValueCollection class and Dictionary.ValueCollection.Enumerator structure


 * Generic Dictionary.ValueCollection class - MSDN


 * Dictionary.ValueCollection.Enumerator structure - MSDN

Generic Comparer class and Generic EqualityComparer class

 * Generic Comparer class - MSDN


 * The Comparer class serves as a base class to easily implement the IComparer interface.


 * The example is the same then for the IComparable except that now a Comparer derived object is given to the List.Sort method instead of implementing the IComparable interface on Point.


 * This way of preceding has 2 advantages:
 * It can be used even if you dont have access to the source code of Point
 * You can have more than one Comparer derived class for the same Point class


 * Generic EqualityComparer class - MSDN

Generic KeyValuePair structure

 * see MSDN

Generic List class, Generic List.Enumerator structure, and Generic SortedList class

 * Generic List class - MSDN
 * A generic list class instance is simply declared using the List syntax where T is the specific type.


 * Generic List.Enumerator structure - MSDN


 * Generic SortedList class - MSDN

Generic Queue class and Generic Queue.Enumerator structure

 * Generic Queue class - MSDN


 * Generic Queue.Enumerator structure - MSDN

Generic SortedDictionary class

 * See MSDN


 * For differences between SortedList and SortedDictionary are explained see MSDN

Generic LinkedList

 * A Generic Linked List represents a doubly linked list and is a general-purpose linked list. It supports enumerators and implements the ICollection interface, consistent with other classes in the .NET Framework.


 * Generic LinkedList class - MSDN


 * Generic LinkedList.Enumerator structure - MSDN


 * Generic LinkedListNode class - MSDN

Generic Stack class and Generic Stack.Enumerator structure

 * Generic Stack class - MSDN


 * Generic Stack.Enumerator structure - MSDN