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

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

Section 1

  • Part 1
    • Topic 2

Manage a group of associated data in a .NET Framework application by using collections. (Refer System.Collections namespace)

  • ArrayList class
  • Collection interfaces
  • Iterators
  • Hashtable class
  • CollectionBase class and ReadOnlyCollectionBase class
  • DictionaryBase class and DictionaryEntry class
  • Comparer class
  • Queue class
  • StoredList class
  • BitArray class
  • Stack class

Summary

The Array List is a dynamically allocated collection of objects. It will automatically increase its capacity as objects are added. Since it holds objects, items inserted into it are boxed, and must be cast back to their specific type.

The collection interfaces include IList, ICollection, and IDictionary.

Iterators are new to .Net 2.0. They enable you to support foreach iteration without implementing the entire IEnumerable interface. The method must return IEnumerable or IEnumerator. It uses the keyword yield return to return each element. You can implement the GetEnumerator Method in the IEnumerable interface to implement the default iterator for the class, or just expose a named method of Type IEnumerable and even accept parameters. The Following example is from msdn.

public class DaysOfTheWeek : System.Collections.IEnumerable
{
          string[] m_Days = { "Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat" };

          public System.Collections.IEnumerator GetEnumerator()
          {
                  for (int i = 0; i < m_Days.Length; i++)
                  {
                         yield return m_Days[i];
                  }
          }
}

class TestDaysOfTheWeek
{
          static void Main()
          {
                  // Create an instance of the collection class
                  DaysOfTheWeek week = new DaysOfTheWeek();

                  // Iterate with foreach
                  foreach (string day in week)
                  {
                         System.Console.Write(day + " ");
                  }
          }
}

The Hashtable Class is a Collection that uses key value pairs stored in a Dictionary Entry object. They keys are hashed when items are entered. See the Resources if you are unfamiliar with this object.

The CollectionBase class is the abstract base class for strongly typed collections. By Inheriting from this class you can expose the basic collection operators (add, insert, remove, index, this, etc) using Strong Types to create a collection that wraps the base List object to expose strongly typed functionality. See the resources for details. The ReadOnlyCollectionBase is a readonly version of this abstract class that can access members through its innerlist property instead of List property.

The DictionaryBase class is the abstract base class for strongly typed collections of key value pairs. Each entry is stored in a DictionaryEntry object

The Comparer Class is the default implementation of the IComparer Interface. It is used to compare strings and accepts a CultureInfo object in its constructor. It can be used as a parameter to Array.Sort to sort a collection.

The Queue class is used to represent a first in first out collection. Use the Enqueue method to add items to the collection.

The SortedList class is used to maintain a HashTable like collection of name value pairs, but sort the collection based on an IComparable implementation of a class that compares the keys.

The BitArray Class is used to hold a compact array of bits, represented as Boolean values.

The Stack class is used to represent a last in first out collection. Use the push method to add items to the collection and pop to remove and return the last item added.

Other Resources & Links:

ArrayList Class
http://msdn2.microsoft.com/en-us/library/7x4b0a97(en-US,VS.80).aspx

Getting to know .Net Collections
http://builder.com.com/5100-6373-1045372.html

Iterators (C# Programming Guide)
http://msdn2.microsoft.com/en-us/library/dscyy5s0.aspx

HashTable Class
http://msdn2.microsoft.com/en-us/library/system.collections.hashtable.aspx

CollectionBase Class
http://msdn2.microsoft.com/en-us/library/7a03ybbb(en-US,VS.80).aspx

ReadOnlyCollectionBase Class
http://msdn2.microsoft.com/en-us/library/system.collections.readonlycollectionbase.aspx

DictionaryBase Class
http://msdn2.microsoft.com/en-us/library/sa198xea(en-US,VS.80).aspx

DictionaryEntry Structure
http://msdn2.microsoft.com/en-us/library/9kth4sbk(en-US,VS.80).aspx

Comparer Class
http://msdn2.microsoft.com/en-us/library/system.collections.comparer.aspx

Queue Class
http://msdn2.microsoft.com/en-us/library/055sfc3z(en-US,VS.80).aspx

SortedList Class
http://msdn2.microsoft.com/en-us/library/w1xa3kh1(en-US,VS.80).aspx

BitArray Class
http://msdn2.microsoft.com/en-us/library/w1xa3kh1(en-US,VS.80).aspx

Stack Class
http://msdn2.microsoft.com/en-us/library/c8hws30f(en-US,VS.80).aspx

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

Basketball Diaries