LINQ, Collections and Generics Interview Questions for .NET Full Stack
25 LINQ, Collections and Generics questions with answers for .net full stack roles — 9 easy, 11 medium, 5 hard.
About LINQ, Collections and Generics
How .NET developers store and query data in memory: List, Dictionary, HashSet, concurrent and frozen collections, generics and constraints, and LINQ operators. Expect questions on deferred execution, IEnumerable versus IQueryable, choosing the right data structure for performance, and writing grouping, joining and ranking queries that also translate correctly to SQL.
When would you choose an array, a List<T> or a LinkedList<T>?
Show answer
When would you use a HashSet<T>?
Show answer
Explain First, FirstOrDefault, Single and SingleOrDefault.
Show answer
Find the second highest salary from a list using LINQ.
Show answer
What are generics and what benefits do they give?
Show answer
Why is Any() usually better than Count() > 0?
Show answer
Sort a list of students by marks descending, then by name ascending.
Show answer
You need to remove inactive users from a List<User> while looping through it with foreach, and you get an InvalidOperationException. How do you fix it?
Show answer
What is deferred execution in LINQ?
Show answer
What is the difference between IEnumerable and IQueryable?
Show answer
What is the difference between Select and SelectMany?
Show answer
Using LINQ, group employees by department and get the count and average salary.
Show answer
Write a LINQ query that joins orders with customers and returns customer name and order total.
Show answer
What are generic constraints? Give examples.
Show answer
Show how yield return works with an example.
Show answer
Your code builds a LINQ query over a database, then calls Count() and later loops over it, and the logs show two SQL queries. Why, and how do you fix it?
Show answer
A job matches 2 lakh uploaded records against 2 lakh existing IDs using list.Where(x => existingIds.Contains(x.Id)) and takes minutes. What is wrong?
Show answer
Show the newer LINQ methods Chunk, DistinctBy and MaxBy.
Show answer
Tell me about a time you improved the performance of slow code.
Show answer
How does Dictionary<TKey, TValue> work internally?
Show answer
Explain covariance and contravariance in C# generics.
Show answer
Several threads update an in-memory Dictionary cache in a singleton service and you see corrupted data and exceptions. What would you use instead?
Show answer
You load 5,000 pincode-to-city mappings at startup and read them millions of times a day from many threads. Which collection would you use?
Show answer
An API endpoint calls _db.Orders.ToList().Where(o => o.CustomerId == id) and is slow as the table grows. Explain and fix it.
Show answer
Frequently asked questions
How important is LINQ, Collections and Generics in .NET Full Stack interviews?
How .NET developers store and query data in memory: List, Dictionary, HashSet, concurrent and frozen collections, generics and constraints, and LINQ operators. Expect questions on deferred execution, IEnumerable versus IQueryable, choosing the right data structure for performance, and writing grouping, joining and ranking queries that also translate correctly to SQL.
How should I use the LINQ, Collections and Generics sheet?
Go top to bottom — easy to hard. Answer before opening each answer, tick what you solved and save misses to Last-Minute Revision.