C# going nuts when I declare variables with the same name as the ones in a lambda
Posted
by Rubys
on Stack Overflow
See other posts from Stack Overflow
or by Rubys
Published on 2010-04-13T14:20:36Z
Indexed on
2010/04/13
14:22 UTC
Read the original article
Hit count: 302
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?
© Stack Overflow or respective owner