During debugging, Visual Studio will track each variable in the current context.
Consider the following code snippet:
void SomeMethod1() { int j = 0; } void SomeMethod2() { int i = 0; }
When the program is interrupted, the current context is SomeMethod2 . At this point, the developer cannot verify what the value of j . This is because int j not a variable in the current context.
The actual reason for the described behavior of the OP:
Visual Studio checks if the variable name exists in the current context, and does not check if the variable itself exists in the current context.
So, if we change the name of the variable j to i in SomeMethod1 , we can suddenly look at its “value”. Imagine how strange it would be if i in SomeMethod2 were a string:

When should you know this?
Whenever you have a piece of code where it does not immediately determine what the current context is. I ran into this problem in the following code snippet:
private double CalculateFast(double d) {
I was debugging Method 2 , but I thought I could look at Method 1 variables. But this was not so, because Method 1 has its own context.
Jordy source share