...

/

Storing Multiple Objects in Collections

Storing Multiple Objects in Collections

Learn about common collection types and discover how to improve collection performance.

One of the most common types of data collection. We can use a collection if we need to store multiple values in a variable. A collection is a data structure in memory that can manage multiple items differently, although all collections have some shared functionality. The most common types in .NET for working with collections are shown in the following table:

Namespace

Example Type(s)

Description

System.Collections

IEnumerable, IEnumerable

Interfaces and base classes used by collections.

System.Collections.Generic

List, Dictionary, Queue, Stack

Introduced in C# 2.0 with .NET Framework 2.0. These collections allow you to specify the type we want to store using a generic type parameter (safer, faster, and more efficient).

System.Collections.Concurrent

BlockingCollection, ConcurrentDictionary, ConcurrentQueue

These collections are safe to use in multithreaded scenarios.

System.Collections.Immutable

ImmutableArray, ImmutableDictionary, ImmutableList, ImmutableQueue

Designed for scenarios where the contents of the original collection will never change, although they can create modified collections as a new instance.

...