C# going nuts when I declare variables with the same name as the ones in a lambda
- by Rubys
I have the following code (generates a quadratic function given the a, b, and c)
Func<double, double, double, Func<double, double>> funcGenerator = (a, b, c) => f => f * f * a + b * f + c;
Up until now, lovely.
But then, if i try to declare a variable named a, b, c or f, visual studio pops a "A local variable named 'f' could not be declared at this scope because it would give a different meaning to 'f' which is used in a child scope."
Basically, this fails, and I have no idea why, because a child scope doesn't even make any sense.
Func funcGenerator = (a, b, c) = f = f * f * a + b * f + c;
var f = 3; // Fails
var d = 3; // Fine
What's going on here?