Introduction
When working with collections and data in C#, developers often come across three commonly used interfaces: IEnumerable, IQueryable, and ICollection. At first glance, they may look similar because all of them deal with collections of data. However, they serve different purposes and are used in different scenarios.
Understanding the difference between these three is very important, especially when working with databases, LINQ queries, and performance optimization.
In this article, we will break down each interface in simple words, understand how they work, and see the key differences with examples.
What is IEnumerable?
IEnumerable is the most basic interface used for iteration over a collection. It allows you to loop through a collection one item at a time.
Key Points of IEnumerable
Works with in-memory collections
Supports forward-only iteration
Uses LINQ to Objects
Executes queries immediately
Example of IEnumerable
IEnumerable<int> numbers = new List<int> { 1, 2, 3, 4, 5 };
var evenNumbers = numbers.Where(n => n % 2 == 0);
foreach (var num in evenNumbers)
{
Console.WriteLine(num);
}
In this example, filtering happens in memory after the data is already loaded.
What is IQueryable?
IQueryable is more advanced and is mainly used when working with databases. It allows queries to be executed on the database side instead of in memory.
Key Points of IQueryable
Works with remote data sources (like databases)
Uses LINQ to Entities
Supports query translation to SQL
Executes queries lazily (deferred execution)
Example of IQueryable
IQueryable<Student> students = dbContext.Students;
var result = students.Where(s => s.Age > 18);
foreach (var student in result)
{
Console.WriteLine(student.Name);
}
Here, the filtering is done in the database, not in memory, which improves performance.
What is ICollection?
ICollection is used when you need more control over a collection. It allows you to add, remove, and count elements.
Key Points of ICollection
Supports modification (Add, Remove, Clear)
Provides Count property
Works with in-memory collections
Inherits from IEnumerable
Example of ICollection
ICollection<string> names = new List<string>();
names.Add("John");
names.Add("Alice");
Console.WriteLine(names.Count);
This interface is useful when you need to manage the collection directly.

Join the conversation! Your thoughts help the community grow.