Collections in Microsoft .NET

December 23, 2015 0 By admin_manish

Collection in .NET is a group of records treated as one logical unit. The .NET Framework provides specialized classes for data storage and retrieval. These classes provide support for stacks, queues, lists, and hash tables. Most collection classes implement the same interfaces, and these interfaces may be inherited to create new collection classes that fit more specialized data storage needs.

Collection Classes have the following properties:

  1. Collection classes are defined as part of the System.Collections or System.Collections.Generic namespace.
  2. Most collection classes derive from the interfaces ICollectionIComparer, IEnumerable,IListIDictionary, and IDictionaryEnumerator and their generic equivalents.
  3. Using generic collection classes provides increased type-safety and in some cases can provide better performance, especially when storing value types. For more information, see Benefits of Generics.

There are four categories of collection:

  1. Index based collection – Help to get the record based on internally generated index for each collection. Examples:
    a. Array
    b. List
  2. Key-value collection – Help to get the record by using user defined key. Examples:
    a. Hashtable
    b. Shorted List
  3. Prioritized collection: Access the elements based on specific sequence like FIFO or LIFO. Examples:
    a. Stacks
    b. Queues
  4. Specialized collection. Examples:
    a. String Collections
    b. Hybrid dictionary – Start as list but later as hashtable