That is some unfortunate wording. Forget about that sentence for a second and let's talk about scopes.
Simplifying, we can assume that a local variable is in scope in the entire block that encloses it.
void Foo()
{
var x; // x is in scope now
if (...)
{
var y; // y is in scope now
...
} // y exits scope
} // x exits scope
This is not how it works exactly, but it's a useful model. In the above code, referring to y outside of the if block is an error, since there is no y in scope.
This should be enough to explain why your code doesn't work. The done variable is in scope for the entirety of the Main method, but it's not in scope in TestField.
The author of the statement is most likely trying to convey the semantics of closures. Anonymous functions create closures and can capture variables from the enclosing scope. What that means is that for example this code:
void Foo()
{
var x = 0;
Action inc = () => { x += 1; };
Action print = () => { Console.WriteLine(x); };
print();
inc();
print();
Console.WriteLine(x);
}
will print
0
1
1
The local variable x is captured by both lambdas assigned to inc and print and is shared between them. The fun part of this is that captured variables can "escape scope":
static (Action inc, Action print) Foo()
{
var x = 0;
Action inc = () => { x += 1; };
Action print = () => { Console.WriteLine(x); };
return (inc, print);
}
static void Main()
{
var (inc, print) = Foo();
inc();
inc();
print(); // Prints 2.
}
Here the x variable lives longer than its scope, since it has to be accessible from the lambda functions even after the Foo method returns.
To solve the puzzle of the "field" part of your quote we must ask ourselves how the compiler achieves that. Here's how:
private sealed class <>c__DisplayClass0_0
{
public int x;
internal void <>b__2()
{
x++;
}
internal void <>b__3()
{
Console.WriteLine(x);
}
}
static (Action inc, Action print) Foo()
{
<>c__DisplayClass0_0 <>c__DisplayClass0_ = new <>c__DisplayClass0_0();
<>c__DisplayClass0_.x = 0;
Action inc = new Action(<>c__DisplayClass0_.<>b__2);
Action print = new Action(<>c__DisplayClass0_.<>b__3);
return (item, item2);
}
static void Main()
{
(inc, print) = Foo();
inc();
inc();
print();
}
This is more-less what the compiler generates. The <>c__DisplayClass0_ is a class generated for the anonymous functions. Its name is not expressible in valid C#. As you can see, the local variable is converted into a field in the class, anonymous functions become methods of that class and they both reference the same shared field.
So you cannot normally access that field from different scopes (thank goodness you can't, that would enable some real nasty spaghetti!), unless you start invoking reflection and other dark magic.