I'm preparing a LINQ section in interview questions for senior programmers. What are the most interesting questions in LINQ to include? And why?
8 Answers
Some of the things you can ask would be like.
- Why the
varkeyword is used and when it is the only way to get query result ? - What is Deferred Execution ?
- Explain Query Expression syntax, Fluent Syntax, Mixed Queries.
- What are Interpreted Queries ?
- Use of
IQueryableandIEnumerableinterfaces. - Use of
letandintokeyword, and how they help in making Progressive queries but still keep Deferred execution - What are Expression Trees ?
Update:
- 656
Ask them to give examples of times when they would tend to not use LINQ and why, even though it would be possible (and ReSharper excitedly suggests it).
- 301
- 1
- 5
You could start but asking what language features that were introduced in C# 3 are needed to support LINQ. Does the candidate understand how features like the var keyword as well as anonymous types, lambda expressions and extension methods were needed to enable LINQ?
- 161
How about some coding questions, like:
- Give then non-LINQ code that would be better done in LINQ and get them to translate it.
- Give them some LINQ and get them to unravel and re-write in plain C# (better yet, find an example where the non-LINQ version is better or more easily understood)
- Ask them to solve some problem and show with/without LINQ and get them to explain which is better, and why.
Text book questions are fine (e.g. why use var), but to really find out if they understand just get them to write code.
- 5,264
If you're looking for a question to which you'd get "interesting" answers, you could ask them why they think most linq examples assign using the "var" keyword on the LHS... there's no right answer and you could probably get some understanding of the type of person they are from what they say.
- 317
Ask them about expression trees. How the linq transforms into sql on the database server the difference between linq extension methods and linq query's
Depends what you are trying to get out of them.
what are situations where you would use First and when to use FirstOrDefault?
what problem does LINQ solve?
what happens when you wrap the query in .ToList?
- 13,324
Ask them to build a small rules engine, using Func[]rules{}. Each rule has to be true, the array replacing case or if statements.
I just started on linq and lambdas but figure this is a nice test of problem solving and linq literacy.
In addition to the more qualified suggestions on here.
- 9