Collections

Collections are basically group of similar or related records or objects that can be treated as a one logical unit.Collections classes provide ease for data storage and retrieval.

.Net collections can be segregated as

  1. Index based.
  2. Key Value pair.
  3. Prioritized Collections.
  4. Specialized Collections.

Indexed based

The collections of this type can be accessed  using the index numbers.

Eg: Array a[0]= 35;

Collections which allow index access include

  • Array
  • ArrayList

Key Value Pair

The elements in this type are stored as pair. For every unique key there will be an associated value.The value can be accessed using the key.

Collections of this type include

  • HashTable
  • Dictionary

Prioritized Collections

These provide some special set of constraints on the order  of storage and retrieval of elements like FIFO(First In First Out ) or LIFO(Last in First Out).

Collections of this type include

  • Queue (FIFO)
  • Stacks (LIFO)

Specialized Collections

They mean for a specific type or functionality like String collections and hybrid dictionary which starts as a list and become a hash table.

Collections can also be classsifed depending on genericity.

  1. Generic
  2. Non- Generic Collections

Generic Collections

Non-Generic Collections

Introduced in .Net Framework 2.0 Introduced since .Net Framework 1.0
Present in System.Collections.Generic namespace. Present in System.Collections namespace
Type Safe at compile time. Loosly Typed.
Accepts a type parameter when they are constructed. Doesn’t require any type parameter.
Stores the elements as  type given in parameters Stores the elements as Object
Doesn’t require casting Requires Casting to and from Object type.
Stores only one type of elements in a given collection. Can Stored multi type elements in a given collection.
Better Performance Performance bottlenecks.
Generic Collections include

  • Dictionary
  • List
  • Queue
  • Stack
  • SortedList
  • SortedDictionary
  • LinkedList
Non-Generic Collections include

  • HashTable
  • ArrayList
  • Queue
  • Stack
  • SortedList
KeyValuePair is a  generic structure for enumeration. DictionaryEntry is a non generic structure for enumeration.
Advertisements