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.
junk is the index of of the currently processed element - see http://msdn.microsoft.com/en-us/library/bb548775.aspx
Much more readable and understable would be
var nn = nums.TakeWhile((n, index) => n > index);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With