why is x in the finally block value 1 instead of being "already" defined or has a default value of 0?
What you see is a debugger connecting characters. It does not matter at all, and in fact, if you try to use it, you will get an unrecognized variable error.
Now why doesn't it show, as already defined, is another question. The answer is that {} defines the declaration space. (In C #, variables are defined at the branch level, not the function level). They are in two different ad spaces and why this is allowed. The first x cannot spill where the second x defined.
What you have is different from
void foo () { var x = 2; if (true){ var x = 3; } }
It is unacceptable.
source share