Master technical and career interviews with structured answers—short definition, real examples, pitfalls, and how to answer in 60–90 seconds.
Short answer: var listA = employees.Take(3); var listB = employees.Skip(2); var common = listA.Select(e => e.Id) .Intersect(listB.Select(e => e.Id)); Example code var listA = employees.Take(3); var listB = employee…
Short answer: var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(l…
Short answer: Skip top 2 highest salaries and take next 2 var result = employees .OrderByDescending(e => e.Salary) .Skip(2) .Take(2); Skip top 2 highest salaries and take next 2 var result = employees .OrderByDescendi…
Short answer: bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(…
Short answer: bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == &quo…
Short answer: var hrList = employees This forces query execution (immediate execution). var hrList = employees This forces query execution (immediate execution). Real-world example (ShopNest) ShopNest filters active prod…
Short answer: This forces query execution (immediate execution). Real-world example (ShopNest) ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL…
Short answer: var taxResult = from e in employees select new { e.Name, Tax = tax }; let stores computed value for reuse. Example code var taxResult = from e in employees select new { e.Name, Tax = tax }; let stores compu…
Short answer: let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed v…
Short answer: foreach (var emp in query) Console.WriteLine(emp.Name); ✅ Output includes “Frank” — because query is executed at enumeration time. var query = employees.Where(e => e.Salary > 70000); employees.Add(new…
Short answer: Why is LINQ deferred? var query = employees.Where(e => e.Salary > 70000); employees.Add(new Employee { Id = 6, Name = "Frank", Department = "IT", Salary = 90000 }); foreach (var em…
Short answer: Get top 3 highest-paid employees var top3 = employees .OrderByDescending(e => e.Salary) .Take(3); Get top 3 highest-paid employees var top3 = employees .OrderByDescending(e => e.Salary) .Take(3); Get…
Short answer: Get bottom 2 lowest-paid employees var bottom2 = employees .OrderBy(e => e.Salary) .Take(2); Get bottom 2 lowest-paid employees var bottom2 = employees .OrderBy(e => e.Salary) .Take(2); Get bottom 2 l…
Short answer: var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select…
Short answer: Get names of employees whose names start with 'A' var namesStartingA = employees .Where(e => e.Name.StartsWith("A")) .Select(e => e.Name); Follow : Get names of employees whose names start w…
Short answer: Get total salary by department var totalByDept = employees .GroupBy(e => e.Department) .Select(g => new { Department = g.Key, Total = g.Sum(e => e.Salary) }); Get total salary by department var tot…
Short answer: var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n =>…
Short answer: Flatten list of lists using SelectMany List<List<int>> numbers = new() { new() { 1, 2 }, new() { 3, 4 }, new() { 5 } var flat = numbers.SelectMany(n => n); Flatten list of lists using SelectM…
Short answer: Use Distinct() on names var distinctNames = employees .Select(e => e.Name) .Distinct(); Use Distinct() on names var distinctNames = employees .Select(e => e.Name) .Distinct(); Use Distinct() on names…
Short answer: double[] salaryArray = employees Real-world example (ShopNest) ShopNest maps entities to DTOs with .Select(o => new OrderSummaryDto { Id = o.Id, Total = o.Total }) so the API does not leak internal field…
Short answer: Convert list of salaries to array double[] salaryArray = employees .Select(e => e.Salary) .ToArray(); Convert list of salaries to array double[] salaryArray = employees .Select(e => e.Salary) .ToArray…
Short answer: var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g…
Short answer: Find duplicate departments var duplicateDepts = employees Follow : .GroupBy(e => e.Department) .Where(g => g.Count() > 1) .Select(g => g.Key); Find duplicate departments var duplicateDepts = emp…
Short answer: Compare LINQ to SQL vs LINQ to Objects? Answer: LINQ to Objects runs in memory on collections (List<T>, arrays). LINQ to SQL/EF builds expression trees and translates to SQL queries. Real-world exampl…
Short answer: var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup va…
LINQ LINQ Tutorial · LINQ
Short answer: var listA = employees.Take(3); var listB = employees.Skip(2); var common = listA.Select(e => e.Id) .Intersect(listB.Select(e => e.Id));
var listA = employees.Take(3);
var listB = employees.Skip(2);
var common = listA.Select(e => e.Id)
.Intersect(listB.Select(e => e.Id));
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id)…
Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id));
var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id)); var onlyInA = listA.Select(e => e.Id) .Except(listB.Select(e => e.Id));
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: Skip top 2 highest salaries and take next 2 var result = employees .OrderByDescending(e => e.Salary) .Skip(2) .Take(2); Skip top 2 highest salaries and take next 2 var result = employees .OrderByDescending(e => e.Salary) .Skip(2) .Take(2); Skip top 2 highest salaries and take next 2 var result = employees .OrderByDescending(e => e.Salary) .Skip(2) .Take(2);… Skip top 2 highest salaries and take next 2 var result =…
employees .OrderByDescending(e => e.Salary) .Skip(2) .Take(2);
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary >…
bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000); bool allHigh = employees.All(e => e.Salary > 50000);
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department ==…
"Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal");
bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal"); bool anyLegal = employees.Any(e => e.Department == "Legal");
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: var hrList = employees This forces query execution (immediate execution). var hrList = employees This forces query execution (immediate execution).
ShopNest filters active products with products.Where(p => p.IsActive && p.Stock > 0) before showing the catalog.
LINQ LINQ Tutorial · LINQ
Short answer: This forces query execution (immediate execution).
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: var taxResult = from e in employees select new { e.Name, Tax = tax }; let stores computed value for reuse.
var taxResult = from e in employees
select new { e.Name, Tax = tax }; let stores computed value for reuse.
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse.
let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse. let stores computed value for reuse.
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: foreach (var emp in query) Console.WriteLine(emp.Name); ✅ Output includes “Frank” — because query is executed at enumeration time. var query = employees.Where(e => e.Salary > 70000); employees.Add(new Employee { Id = 6, Name = "Frank", Department =
"IT", Salary = 90000 });
ShopNest builds a LINQ query for search filters, then calls ToListAsync() once in the repository—so the SQL runs one time, not inside a loop.
LINQ LINQ Tutorial · LINQ
Short answer: Why is LINQ deferred? var query = employees.Where(e => e.Salary > 70000); employees.Add(new Employee { Id = 6, Name = "Frank", Department = "IT", Salary = 90000 }); foreach (var emp in query) Console.WriteLine(emp.Name); ✅ Output includes “Frank” — because query is executed at enumeration time. Why is LINQ deferred? var query =… employees.Where(e =>…… e.Salary > 70000); employees.Add(new Employee { Id = 6, Name =…
"Frank", Department = "IT", Salary = 90000 }); foreach (var emp in query) Console.WriteLine(emp.Name); ✅ Output includes “Frank” — because query is executed at enumeration time.
ShopNest builds a LINQ query for search filters, then calls ToListAsync() once in the repository—so the SQL runs one time, not inside a loop.
LINQ LINQ Tutorial · LINQ
Short answer: Get top 3 highest-paid employees var top3 = employees .OrderByDescending(e => e.Salary) .Take(3); Get top 3 highest-paid employees var top3 = employees .OrderByDescending(e => e.Salary) .Take(3); Get top 3 highest-paid employees var top3 = employees .OrderByDescending(e => e.Salary) .Take(3); Get top 3 highest-paid employees var top3 = employees… OrderByDescending(e => e.Salary) .Take(3);
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: Get bottom 2 lowest-paid employees var bottom2 = employees .OrderBy(e => e.Salary) .Take(2); Get bottom 2 lowest-paid employees var bottom2 = employees .OrderBy(e => e.Salary) .Take(2); Get bottom 2 lowest-paid employees var bottom2 = employees .OrderBy(e => e.Salary) .Take(2); Get bottom 2 lowest-paid employees var bottom2 = employees .OrderBy(e =>…
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e =>…
var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name); var namesStartingA = employees .Select(e => e.Name);
ShopNest filters active products with products.Where(p => p.IsActive && p.Stock > 0) before showing the catalog.
LINQ LINQ Tutorial · LINQ
Short answer: Get names of employees whose names start with 'A' var namesStartingA = employees .Where(e => e.Name.StartsWith("A")) .Select(e => e.Name); Follow : Get names of employees whose names start with 'A' var namesStartingA = employees .Where(e => e.Name.StartsWith("A")) .Select(e => e.Name); Follow : Get names of employees whose names start with 'A' var… namesStartingA = employees .Where(e => e.Name.StartsWith("A"))…
Select(e => e.Name); Follow : Get names of employees whose names start with 'A' var namesStartingA = employees .Where(e => e.Name.StartsWith("A")) .Select(e => e.Name); Follow :
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: Get total salary by department var totalByDept = employees .GroupBy(e => e.Department) .Select(g => new { Department = g.Key, Total = g.Sum(e => e.Salary) }); Get total salary by department var totalByDept = employees .GroupBy(e => e.Department) .Select(g => new { Department = g.Key, Total = g.Sum(e => e.Salary) }); Real-world… example (ShopNest) ShopNest…… uses LINQ to query orders: filter by date, project to a…
summary DTO, and order by total—readable C# that becomes SQL under EF Core. Get total salary by department var totalByDept = employees .GroupBy(e => e.Department) .Select(g => new { Department = g.Key, Total = g.Sum(e => e.Salary) }); Get total salary by department var totalByDept = employees .GroupBy(e => e.Department) .Select(g => new { Department = g.Key, Total = g.Sum(e => e.Salary) }); Real-world… example (ShopNest) ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n);
var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n); var flat = numbers.SelectMany(n => n);
ShopNest maps entities to DTOs with .Select(o => new OrderSummaryDto { Id = o.Id, Total = o.Total }) so the API does not leak internal fields.
LINQ LINQ Tutorial · LINQ
Short answer: Flatten list of lists using SelectMany List<List<int>> numbers = new() { new() { 1, 2 }, new() { 3, 4 }, new() { 5 } var flat = numbers.SelectMany(n => n); Flatten list of lists using SelectMany List<List<int>> numbers = new() { new() { 1, 2 }, new() { 3, 4 }, new() { 5 } var flat = numbers.SelectMany(n => n); Real-world example… (ShopNest) ShopNest maps…… entities to DTOs with .Select(o => new OrderSummaryDto { Id…
= o.Id, Total = o.Total }) so the API does not leak internal fields. Flatten list of lists using SelectMany List<List<int>> numbers = new() { new() { 1, 2 }, new() { 3, 4 }, new() { 5 } var flat = numbers.SelectMany(n => n); Flatten list of lists using SelectMany List<List<int>> numbers = new() { new() { 1, 2 }, new() { 3, 4 }, new() { 5 } var flat = numbers.SelectMany(n => n); Real-world example… (ShopNest) ShopNest maps entities to DTOs with .Select(o => new OrderSummaryDto { Id = o.Id, Total = o.Total }) so the API does not leak internal fields.
LINQ LINQ Tutorial · LINQ
Short answer: Use Distinct() on names var distinctNames = employees .Select(e => e.Name) .Distinct(); Use Distinct() on names var distinctNames = employees .Select(e => e.Name) .Distinct(); Use Distinct() on names var distinctNames = employees .Select(e => e.Name) .Distinct(); Use Distinct() on names var distinctNames = employees .Select(e => e.Name) .Distinct();
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: double[] salaryArray = employees
ShopNest maps entities to DTOs with .Select(o => new OrderSummaryDto { Id = o.Id, Total = o.Total }) so the API does not leak internal fields.
LINQ LINQ Tutorial · LINQ
Short answer: Convert list of salaries to array double[] salaryArray = employees .Select(e => e.Salary) .ToArray(); Convert list of salaries to array double[] salaryArray = employees .Select(e => e.Salary) .ToArray(); Convert list of salaries to array double[] salaryArray = employees .Select(e => e.Salary) .ToArray(); Convert list of salaries to array double[]… salaryArray = employees .Select(e => e.Salary) .ToArray();
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key);
var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key); var duplicateDepts = employees .Select(g => g.Key);
ShopNest filters active products with products.Where(p => p.IsActive && p.Stock > 0) before showing the catalog.
LINQ LINQ Tutorial · LINQ
Short answer: Find duplicate departments var duplicateDepts = employees Follow : .GroupBy(e => e.Department) .Where(g => g.Count() > 1) .Select(g => g.Key); Find duplicate departments var duplicateDepts = employees Follow : .GroupBy(e => e.Department) .Where(g => g.Count() > 1) .Select(g => g.Key); Find duplicate departments var duplicateDepts = employees Follow :… GroupBy(e => e.Department) .Where(g => g.Count() > 1) .Select(g…
=> g.Key); Find duplicate departments var duplicateDepts = employees Follow : .GroupBy(e => e.Department) .Where(g => g.Count() > 1) .Select(g => g.Key);
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: Compare LINQ to SQL vs LINQ to Objects? Answer: LINQ to Objects runs in memory on collections (List<T>, arrays). LINQ to SQL/EF builds expression trees and translates to SQL queries.
ShopNest uses LINQ to query orders: filter by date, project to a summary DTO, and order by total—readable C# that becomes SQL under EF Core.
LINQ LINQ Tutorial · LINQ
Short answer: var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup
var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup var allDepts = from d in departments into empGroup
ShopNest maps entities to DTOs with .Select(o => new OrderSummaryDto { Id = o.Id, Total = o.Total }) so the API does not leak internal fields.