Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

share|improve this question
add comment

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

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

11 Answers

up vote 26 down vote accepted

Some of the things you can ask would be like.

  • Why the var keyword 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 IQueryable and IEnumerable interfaces.
  • Use of let and into keyword, and how they help in making Progressive queries but still keep Deferred execution
  • What are Expression Trees ?


Update:

For Detailed answers see this nice post by Oleksii

share|improve this answer
7  
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
add comment

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

share|improve this answer
add comment

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?

share|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
    
That's not correct. Anonymous types are required for linq-to-Sql projections, for example to select only certain columns from a table/entity. –  joniba Dec 9 '13 at 21:51
add comment

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.

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

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
add comment

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

share|improve this answer
add comment
  • 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?

share|improve this answer
    
allows deferred execution. –  linquize Jun 19 '12 at 9:06
    
reduce the chance of using for / foreach loop to improve readability –  linquize Jun 19 '12 at 9:07
add comment

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.

share|improve this answer
add comment

here i have collected lots of Language Integrated Query (LINQ) Interview Questions and Answers

kindly have a look this would help you a lot

Regards,

Akaas Developer

questions-interviews.com

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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