Collections in C#


Collection classes are 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.

Collection classes serve various purposes, such as allocating memory dynamically to elements and accessing a list of items on the basis of an index etc. These classes create collections of objects of the Object class, which is the base class for all data types in C#.

Collection represents group of objects. By the help of collections, we can perform various operations on objects such as

  • store object

  • update object

  • delete object

  • retrieve object

  • search object, and

  • sort object

Ways to Work with Collection

There are 3 ways to work with collections. The three namespaces are given below:

  1. System.Collections.Generic classes

  2. System.Collections classes (Now deprecated)

  3. System.Collections.Concurrent classes

1) System.Collections.Generic classes

The System.Collections.Generic namespace has following classes: