← Back to Article List         
Collections in C# – Quick Revision

Collections in C# – Quick Revision

Published on 20 Oct 2026     3 min read C#
C# - Fundamentals
 

C# Collections – Quick Revision

1. What is a Collection in C#?

A Collection in C# is used to store, manage, and manipulate multiple objects or values in a single variable.

Collections provide built-in methods for adding, removing, searching, sorting, and accessing elements.

Example:

List<int> numbers = new List<int> { 10, 20, 30 };

numbers.Add(40);
numbers.Remove(20);

foreach (int number in numbers)
{
    Console.WriteLine(number);
}

2. Types of Collections in C#

C# Collections
│
├── 1. Non-Generic Collections
│   ├── ArrayList
│   ├── Hashtable
│   ├── Stack
│   └── Queue
│
├── 2. Generic Collections
│   ├── List<T>
│   ├── Dictionary<TKey, TValue>
│   ├── HashSet<T>
│   ├── SortedSet<T>
│   ├── Stack<T>
│   ├── Queue<T>
│   └── LinkedList<T>
│
├── 3. Concurrent Collections
│   ├── ConcurrentDictionary
│   ├── ConcurrentQueue
│   ├── ConcurrentStack
│   └── ConcurrentBag
│
└── 4. Immutable Collections
    ├── ImmutableList
    ├── ImmutableDictionary
    └── ImmutableHashSet

3. Important Collections with Examples

Collection

Description

Use Case

List<T>

Dynamic-sized list

Employee records

Dictionary<K,V>

Key-value pairs

Employee ID and name

HashSet<T>

Stores unique values

Remove duplicates

SortedSet<T>

Unique values in sorted order

Sorted unique IDs

Stack<T>

LIFO (Last In, First Out)

Undo operation

Queue<T>

FIFO (First In, First Out)

Job processing

LinkedList<T>

Doubly linked nodes

Frequent node insertion/removal

ArrayList

Non-generic dynamic list

Legacy applications

Hashtable

Non-generic key-value collection

Legacy applications

4. Generic vs Non-Generic Collections

Generic

Non-Generic

Type-safe

Stores values as object

Better type checking

Requires casting when retrieving values

Avoids boxing for value types

May cause boxing/unboxing

List<int>

ArrayList

Recommended for modern C#

Mainly used in legacy code

5. Common Collection Interfaces

Interface

Purpose

IEnumerable<T>

Supports iteration using foreach

ICollection<T>

Supports Add, Remove, Count

IList<T>

Supports index-based access

IDictionary<K,V>

Represents key-value collections

IReadOnlyCollection<T>

Provides read-only collection access

IReadOnlyList<T>

Provides read-only index-based access

IQueryable<T>

Supports query composition through providers such as EF Core

6. Important Interview Questions

Q1. What is the difference between Array and List?

Array has a fixed size, whereas List<T> can grow or shrink dynamically.

Q2. List vs Dictionary?

List<T> stores elements accessed by index. Dictionary<TKey,TValue> stores key-value pairs and supports fast key-based lookup.

Q3. HashSet vs List?

HashSet<T> stores unique elements, whereas List<T> allows duplicates and maintains insertion order.

Q4. Stack vs Queue?

Stack follows LIFO, whereas Queue follows FIFO.

Q5. IEnumerable vs IQueryable?

IEnumerable<T> supports iteration over data. IQueryable<T> represents queries that a provider, such as EF Core, can translate into SQL.

Q6. Which collection is thread-safe?

Collections such as ConcurrentDictionary, ConcurrentQueue, and ConcurrentBag support thread-safe operations.

Q7. Which collection is commonly used in ASP.NET Core?

List<T> and Dictionary<TKey,TValue> are common. EF Core also frequently uses IQueryable<T> for database queries.

Key Points:

  • Prefer generic collections for type safety.

  • Use List<T> for ordered, index-based data.

  • Use Dictionary<TKey,TValue> for key-based lookup.

  • Use HashSet<T> for uniqueness.

  • Use concurrent collections for multithreaded access.

  • Use immutable collections when data should not change after creation.