Monday, October 26, 2009

Collections

The System.Collections namespace contains non-generic classes and interfaces that pertain to gathering and sorting collections of objects and value types.

Here is the MSDN reference for System.Collections.

Classes:




  • ArrayList - Array whose size is dynamically increased as required. Implements IList, IEnumerable. Method arrayList.Add will add an object to the array. Objects can be removed by calling arrayList.Remove(o : Object). ArrayLists can be sorted. Any type of object can be stored, including null.


  • BitArray - Compact Array of bits (bool values).


  • CaseInsensitiveComparer - Compares objects for equivalence, ignoring case on Strings.


  • CollectionBase - Abstract base class for strongly-typed Collection of objects.


  • Comparer - Compares objects for equivalence, case-sensitive for Strings. Default implementation of IComparer interface.


  • DictionaryBase - abstract base class for key-value pair collections. Each entry is stored as a DictionaryEntry struct (structure that represents a key-value pair). Consequently, a foreach iteration over an implementation of DictionaryBase will be a foreach (DictionaryEntry de : dictionary).

  • Hashtable - Implementation of key-value pair collection. If an add is called, but there is already a DictionaryEntry with this key, an Exception is thrown. hashtable.ContainsKey should be called to make sure that it doesn't exist.

  • Queue - FIFO collection of objects. Method Enqueue adds to the Queue, Dequeue removes from the queue using FIFO. Peek will return the same value as Dequeue, but will not actually remove the object from the Queue.

  • ReadOnlyCollectionBase - Similar to CollectionBase, only read-only.

  • SortedList - Collection of key-value pairs, where the keys are sorted.

  • Stack - LIFO collection of objects. Method Push adds to the Stack, Pop removes from the Stack using LIFO. Peek will return the same value as Pop, but will not actually remove the object from the Stack.

Structs:



  • DictionaryEntry - represents a key-value pair for a collection that implements IDictionary.

Interfaces:



  • ICollection - base interface for classes in System.Collections namespace. Extends IEnumerable.

  • IComparer - contract defines a single method, Compare(a : Object, b: Object) : int. Will return negative if a is less than b, 0 if a and b are equal, positive if a is greater than b.

  • IDictionary - collection of key-value pairs (which are DictionaryEntry structs). 3 types of IDictionary implementations: read-only, fixed-size, variable-size.

  • IEnumerable - Provides GetEnumerator method, which must be implemented in order to support the foreach keyword.

  • IList - Collection of objects that can be accessed by index.

No comments:

Post a Comment