C# LINQ Teaser
Another great interview question.
Will the following code compile and if yes what will be the result of it ?
static void Main(string[] args)
{
int[] array = new[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Func<int, int> func = i => {
Console.Write(array[i]);
return i;
};
var result = array.Where(e => e <= func(2)).ToArray ();
}
A few posts you might find interesting:
Categories: C#, Interview Questions, Programming, Teasers, Tips & Tricks C#, c#.net, c-sharp, delegate, interview, Interview Questions, lambda, linq, net c#, Puzzle, puzzles, tezer, Tips and Tricks, visual c#

It will print the number 3 to stdout 10 times (so ‘*CORRECT ANSWER’), and result will be {1,2}. Tricky question though, easy to get it wrong and say ‘12345678910′
@Paul Betts
This is what tricky question is supposed to do
I’m replacing your CORRECT answer with “CORRECT ANSWER”, so others will have the opportunity to solve it on their own.
I would simply refuse to answer on the basis that the code is not written using the best practice of writing easily understood code due to naming conventions used
Seriously, nice one. I had to read it like 10 times before I got the answer. Albeit I don’t specialize in the MS stack alone.
Great Teaser.
More, More…