# Collections

## `System.Collections` classes

The classes in the `System.Collections` namespace do not store elements as specifically typed objects, but as objects of type `Object`.

<table><thead><tr><th width="129">Class</th><th>Description</th></tr></thead><tbody><tr><td>ArrayList</td><td>Represents an array of objects whose size is dynamically increased as required.</td></tr><tr><td>Hashtable</td><td>Represents a collection of key/value pairs that are organized based on the hash code of the key.</td></tr><tr><td>Queue</td><td>Represents a first in, first out (FIFO) collection of objects.</td></tr><tr><td>Stack</td><td>Represents a last in, first out (LIFO) collection of objects.</td></tr></tbody></table>

{% embed url="https://docs.microsoft.com/en-us/dotnet/api/system.collections?view=net-6.0" %}

{% hint style="info" %}
The [System.Collections.Specialized](https://docs.microsoft.com/en-us/dotnet/api/system.collections.specialized) namespace provides specialized and strongly typed collection classes, such as string-only collections and linked-list and hybrid dictionaries.
{% endhint %}

## `System.Collections.Generic` classes

A generic collection enforces strong typing by allowing only the desired data type to be added. A generic collection is useful when every item in the collection has the same data type.&#x20;

<table><thead><tr><th width="279">Class</th><th>Description</th></tr></thead><tbody><tr><td><code>Dictionary&#x3C;TKey,TValue></code></td><td>Represents a collection of key/value pairs that are organized based on the key.</td></tr><tr><td><code>List&#x3C;T></code></td><td>Represents a list of objects that can be accessed by index. Provides methods to search, sort, and modify lists.</td></tr><tr><td><code>Queue&#x3C;T></code></td><td>Represents a first in, first out (FIFO) collection of objects.</td></tr><tr><td><code>Stack&#x3C;T></code></td><td>Represents a last in, first out (LIFO) collection of objects.</td></tr></tbody></table>

{% embed url="https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic?view=net-6.0" %}

> #### `Dictionary<TKey, TValue>()`
>
> Dictionary internally stores object in an array, but unlike a list, where objects are added at the end of the array (or at the index), the index is calculated using a hash function.
>
> #### `List<T>`
>
> List internally uses arrays, if it becomes full it'll create a new larger array and copy content from the older array to the new one.

## `System.Collections.Concurrent` classes

A concurrent collection provide efficient thread-safe operations for accessing collection items from multiple threads.

{% embed url="https://docs.microsoft.com/en-us/dotnet/api/system.collections.concurrent?view=net-6.0" %}
