I read this question ( What is the scope of a lambda variable in C #? )
But this is about the scope of the Lambda variable inside the LINQ query.
Now to my question
Let's say I have a very simple LINQ query.
var Foo = FoobBar.Select(x => x);
var x = somefunction();
The compiler says A local variable 'x' cannot be declared in this scope because it would give a different meaning to 'x', which is already used in a 'child' scope to denote something else.
Why is this so? Should a Lambda variable cease to exist when a LINQ query completes?
The EDIT: . After reading the answers, I came to the conclusion that its external x(returned by the function), the volume of which is distributed inside LINQ Query.
source
share