Exam 70-553 - Improve type safety and application performance in a .NET Framework application by using generic collections.

Here is the third installment of my notes on Exam 70-553:

Section 1

  • Part 1
    • Topic 3

Improve type safety and application performance in a .NET Framework application by using generic collections. (Refer System.Collections.Generic namespace)

  • Collection.Generic interfaces
  • Generic Dictionary
  • Generic Comparer class and Generic EqualityComparer class
  • Generic KeyValuePair structure
  • Generic List class, Generic List.Enumerator structure, and Generic SortedList class
  • Generic Queue class and Generic Queue.Enumerator structure
  • Generic SortedDictionary class
  • Generic LinkedList
  • Generic Stack class and Generic Stack.Enumerator structure


There are a number of Generic Interfaces that correspond to interface mentioned in the previous section. They all have similar functionality with the ability to declare type during instantiation. The Interface include: Generic IComparable, Generic ICollection, Generic IList, Generic IComparer, Generic IDictionary, and Generic IEnumerable. Using any of these classes avoids the boxing and unboxing that occurs with the standard interface.

The following three samples come from the C# Generic Interfaces Programming guide mentioned in the resources:

Multiple interfaces can be specified as constraints on a single type, as follows:

Class Stack<T> where T : System.IComparable<T>, IEnumerable<T>

An interface can define more than one type parameter, as follows:

interface IDictionary<K, V>

The same rules of inheritance apply to interfaces as to classes:

interface IMonth<T> { }

interface IJanuary : IMonth<int> { } //No error
interface IFebruary<T> : IMonth<int> { } //No error
interface IMarch<T> : IMonth<T> { } //No error
//interface IApril<T> : IMonth<T, U> {} //Error

The Generic dictionary and the Generic Sorted Dictionary are like the regular dictionarys except you can strong type the key and the value. For example:

Dictionary<string, string> StringDictionary = new Dictionary<string, string>();

Would create a Dictionary instance that can only accept strings as its name value paris .

The Generic Comparer is designed for use with the SortedList and SortedDictionary Generic Classes. The types of the instances are constrained in that they must implement IComparable or the Generic IComparable Interfaces.

The Generic EqualityComparer Class is designed to override the Equals or GetHashCode methods of implementations of Generic Collections.

The Generic Key Value Pair is used by the Generic Dictionary class to define the type of key and type of value being stored in the Dictionary.

The Generic List and Sorted List are used to easily create a strongly typed list of objects that can be accessed by index. Below is an example of creating an instance of the List:

List<string> StringList = new List<string>();

The Generic Queue Class is used to easily create a strongly typed collection of first in first out objects.

The Generic Stack Class is used to easily create a strongly typed collection of last in first out objects.

The Generic List Enumerator structure, Generic Queue Enumerator structure, and Generic Stack Enumerator structure are used for creating a Generic Method that returns a Enumerator or implemnentation of IEnumerable. You specify the type when you use it. The List Structure is for use with the Generic List, the Queue structure is for use with the Generic Queue, and the Stack structure is for use with the Generic Stack. Don’t get confused by the fact that these are structure, all these classes implement the Enumerable methods like MoveNext and Current.

Other Resources & Links:

Generic Interfaces (C# Programming Guide)

Dictionary Generic Class

Comparer Generic Class

KeyValuePair Generic Structure

List Generic Class

Queue Generic Class

Stack Generic Class

Introducing .NET Generics

Generics (C# Programming Guide)

Generics for C# and .NET CLR

Exam 70-553 - Implement .NET Framework interfaces to cause components to comply with standard contracts.

Exam 70-553 - Manage a group of associated data in a .NET Framework application by using collections.