C# Interview

LINQ & Querying

C# interview questions covering linq & querying.

10 Questions Filter by level

Interview questions

Open a question for the full answer, code and interview guidance.

10 Results
41
Mid-LevelIntermediate

What is LINQ in C#?

LINQ stands for Language Integrated Query. It provides a consistent, strongly typed way to query collections, arrays, databases, XML, and other data sources directly from C#.

42
Mid-LevelIntermediate

What is the difference between LINQ query syntax and method syntax?

LINQ supports query syntax and method syntax. Query syntax resembles SQL, while method syntax uses extension methods and lambda expressions.

43
Mid-LevelIntermediate

What is deferred execution in LINQ?

Deferred execution means a LINQ query is defined first but is not necessarily executed immediately. Execution occurs when the result is enumerated, for example by foreach, ToList, ToArray, First, Count, or another terminal operation.

44
Mid-LevelIntermediate

What is the difference between Where() and Select() in LINQ?

Where filters elements based on a condition. Select transforms or projects each element into another shape or value.

45
Mid-LevelIntermediate

What is the difference between First(), FirstOrDefault(), Single(), and SingleOrDefault()?

First returns the first matching element and throws an exception if no element exists. FirstOrDefault returns the first matching element or the default value when no element exists.

46
Mid-LevelIntermediate

What is the difference between Any() and Count() in LINQ?

Any checks whether at least one element exists or satisfies a condition. Count calculates the number of matching elements.

47
Mid-LevelIntermediate

What are OrderBy(), OrderByDescending(), ThenBy(), and ThenByDescending()?

These LINQ operators sort sequences. OrderBy sorts by the primary key in ascending order, while OrderByDescending sorts in descending order.

48
Mid-LevelIntermediate

What is GroupBy() in LINQ?

GroupBy organizes elements into groups based on a key. Each group has a Key and a sequence of matching elements.

49
Mid-LevelIntermediate

What is Join() in LINQ?

Join combines elements from two sequences using matching keys, similar to an SQL INNER JOIN.

50
Mid-LevelIntermediate

What is the difference between Select() and SelectMany()?

Select projects each input element into one output element or object. SelectMany projects each input element into a sequence and then flattens those nested sequences into one sequence.