I wrote the following code and I’m not able to understand how it is executed.
class Program
{
static void Main(string[] args)
{
int[] nums = { 1, 5, 10, 3, 554, 34};
var nn = nums.TakeWhile((n, junk) => n > junk);
nn.Count();
foreach (var a in nn)
{
Console.WriteLine(a);
}
Console.ReadKey();
}
}
First I wrote the TakeWhile expression as n => n > 5. I’m able to understand that. But I just added one more parameter junk. What is junk here? What value is assigned to it during query exeution? How is it giving the output as 1, 5 and 10.
junkis the index of of the currently processed element – see http://msdn.microsoft.com/en-us/library/bb548775.aspxMuch more readable and understable would be