I am trying to solve a question in Project Euler, which is creating a fibonacci series until 4 million, and add the even numbers that come in the series, this is obviously very easy task and I answer it in 2 mins,
int result=2;
int first=1;
int second=2;
int i=2;
while (i < 4000000)
{
i = first + second;
if (i % 2 == 0)
{
result += i;
}
first = second;
second = i;
}
Console.WriteLine(result);
but I want to do it using a lambda expression
My effort is going like
DelType del = (oldVal, newVal) =>((oldVal==0?1:newVal + newVal==1?2:oldVal+newVal) % 2 == 0) ? oldVal + newVal : 0;
int a=del(0, 1);
Kindly suggest how to get this done