IEnumerable vs IQueryable in C# — The Difference That Actually Matters
This blog breaks down the practical difference between IEnumerable and IQueryable — IEnumerable pulls data into memory and filters it there, while IQueryable translates the query and runs it directly on the database, which makes a major performance difference on larger datasets. It covers deferred execution, a common source of production bugs, and explains when to use which. It ends with a follow-up interview question (.AsEnumerable() vs .ToList()) that tends to catch candidates off guard, and positions Kiriti AI as the tool that helps identify these exact concept-level gaps and practice explaining them under pressure.
IEnumerable vs IQueryable in C# — The Difference That Actually Matters in Interviews
If you've prepped for a .NET interview, you've seen this question. It shows up almost every time, at almost every level — fresher, mid, senior. And yet most candidates give an answer that's technically half-right and practically useless the moment the interviewer asks a follow-up.
Let's fix that properly.
The One-Line Difference
IEnumerable executes the query in memory, on the client side, after the data has already been pulled.
IQueryable builds the query as an expression tree and executes it on the data source itself — typically the database — before anything is pulled into memory.
That's the textbook answer. Here's why it actually matters.
Where This Breaks in Real Projects
Imagine you have a list of 100,000 orders in a database, and you want the ones placed this year.
IEnumerable<Order> orders = dbContext.Orders;
var thisYear = orders.Where(o => o.OrderDate.Year == DateTime.Now.Year);
With IEnumerable, this pulls all 100,000 rows into memory first, and then filters them in your application. Your database did almost nothing. Your application did all the work — and paid for it in memory and time.
Now the IQueryable version:
IQueryable<Order> orders = dbContext.Orders;
var thisYear = orders.Where(o => o.OrderDate.Year == DateTime.Now.Year);
This translates into SQL and runs on the database, which returns only the matching rows. Far less data moves across the wire, and the database — which is built for this — does the filtering.
This is the difference interviewers are actually testing for. Not whether you know the definition, but whether you understand where your code executes and what that costs.
Deferred Execution — the Part Everyone Forgets
Both IEnumerable and IQueryable use deferred execution, meaning the query doesn't run the moment you write it — it runs when you actually enumerate it (a foreach, a .ToList(), a .Count(), etc.).
This causes a specific, very real bug: if you build a query, pass it somewhere, and the underlying data changes before it's enumerated, you'll query the changed data — not the data you thought you were working with. Senior candidates are expected to know this because it's a common source of production bugs, especially in loops or when a query is reused across multiple contexts.
When to Use Which
- Use
IQueryablewhen working directly with a data source (like Entity Framework Core against a database) and you want filtering, sorting, and projection to happen at the source. - Use
IEnumerablewhen you're working with data that's already in memory — aList<T>, an array, or data you've deliberately already pulled — since there's no further translation benefit to gain. - A common mistake: converting an
IQueryabletoIEnumerabletoo early (often with an unnecessary.ToList()or.AsEnumerable()) before all your filters are applied. This silently pulls everything into memory before the rest of your query runs — one of the most common causes of the N+1-adjacent performance problems that show up in code review.
The Follow-Up Question You Should Expect
If you answer this well, the natural next question is: "What's the difference between .AsEnumerable() and .ToList() when converting from IQueryable?"
Short answer: .AsEnumerable() switches the execution context to LINQ-to-Objects without materializing the data immediately — it's still deferred. .ToList() executes the query immediately and loads everything into memory as a list, right then. Knowing this distinction is usually what separates a 6/10 answer from a 9/10 answer in an actual interview.
Why This Trips People Up Live, Not Just on Paper
Here's the uncomfortable truth: most developers who read this article will nod along and think "yeah, I know this." But knowing it while reading calmly is different from explaining it clearly, under time pressure, when an interviewer asks a sharp follow-up you didn't anticipate.
This is exactly the kind of question that benefits from being asked out loud, under some pressure, before the real interview — not just read once and filed away.
Kiriti AI runs adaptive mock interviews that generate a domain-specific cheatsheet for exactly this kind of topic, then quizzes you on it later so it actually sticks — instead of fading the way most last-minute reading does.
Try a free mock interview at kiritiai.com and see how well you can actually explain concepts like this one when someone's listening.