C# Collections

A collection in C# is a group of related objects, which are stored together. They are designed to provide a more flexible way of working with groups of objects and offer many enhancements over arrays.

Collections can be split into two categories, generic and non-generic. Non-generic collections can contain elements of different types, so strings and integers, along with other data types can exist in the same collection. These collections reside in the ‘System.Collections’ namespace and are generally slightly easier to code than generic collections. Non-generic collections include:

Generic collections offer type safety, meaning that they only allow elements of the same data type within them, such as strings or integers. All generic collections can be found in the ‘System.Collections.Generic’ namespace. Generic collections include: