I'm preparing a LINQ section in interview questions for senior programmers. What are the most interesting questions in LINQ to include? And why?

link|improve this question
feedback

migrated from stackoverflow.com Apr 20 '11 at 10:29

This question came from our site for professional and enthusiast programmers.

9 Answers

up vote 18 down vote accepted

Some of the things you can ask would be like.

  • Why var keyword is used and when it is the only way to get query result ?
  • What is Deffered Execution ?
  • Explain Query Expression syntax, Fluent Syntax, Mixed Queries.
  • What are Interpreted Queries ?
  • Use of IQueryable and IEnumerable interfaces.
  • Use of let and into keyword, and how they help in making Progressive queries but still keep Deffered execution.
  • What are Expression Trees ?


Update:

For Detailed answers see this nice post by Oleksii

link|improve this answer
6  
Great questions. I might be tempted to give code examples and say "what does this do?" as I'm not totally convinced that you need to know what the term Fluent Syntax is to use and understand it. – user23157 Apr 20 '11 at 12:07
hmmm, And if they Google those topics before hand and memorise it, how does this approach tell you that they can actually do any real world LINQ? – Darknight Apr 20 '11 at 21:57
then as BTyler said above... you can complement above questions with code samples. – Shekhar_Pro Apr 20 '11 at 22:03
1  
This guy blogged about the solutions to all of these questions: blog4work.com/?tag=/LINQ – NickLarsen Jul 17 '11 at 16:36
Just saw the post, nice work :) – Shekhar_Pro Jul 17 '11 at 23:49
feedback

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).

link|improve this answer
feedback

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?

link|improve this answer
For my own curiousity why are anonymous types necessary? They can be used for select results as a convenience but you could equally well define your own classes with named properties can't you? – Rup Apr 20 '11 at 11:09
@Rup | Its just a matter of convenience and a syntactic sugar .. you can of-course create Well Defined Classes (anyway compiler does that for you behind the scene). but while Using LINQ queries you instantly need a type to contain the results... now this doesn't seem productive to keep creating classes for each type and this may lead to more code to and difficult to maintain if result set changes later. – Shekhar_Pro Apr 20 '11 at 13:07
feedback

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.

link|improve this answer
feedback

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.

link|improve this answer
+1. This is really the best way to judge competence. – kirk.burleson Jul 18 '11 at 1:59
feedback

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.

link|improve this answer
feedback

What are some cases where you would use the First() method instead of the Single() method, and vice-versa?

link|improve this answer
feedback

Ask them how to run LINQ on a datatabe or datareader.

link|improve this answer
feedback
  • 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?

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.