Skip to content
Sharp

LINQ interview questions

Query operators, deferred execution, IEnumerable vs IQueryable.

4 questions with answers and explanations · 2 flashcards

Key ideas

  • Most operators (Where, Select, OrderBy) are deferred: nothing runs until you enumerate.
  • ToList(), ToArray(), Count(), First() force immediate execution.
  • IEnumerable<T> runs delegates in memory; IQueryable<T> builds an expression tree a provider (EF Core) translates to SQL.
  • First() throws on empty sequences; FirstOrDefault() returns default.

Questions

  1. What does this program print?What does this code output?Medium
  2. Which LINQ call executes the query immediately?Multiple choiceEasy
  3. Which LINQ method projects each element to a sequence and flattens the results into one sequence? (method name only)Fill in the blankMedium
  4. What happens when you call First() and FirstOrDefault() on an empty List<string>?Multiple choiceMedium