I was debugging my code when I saw something weird. Basically it came down to this:
What you see here is an unsigned int with a negative value...
I also noticed that some surrounding variables didn't have a value pop-up
(?) and others did. But this variable was the only one that had an impossible value.
How is this possible?
I only have C# Visual Studio 2010, so I don't know it this problem exists in other versions or for different languages. I'll change the title and tags accordingly if this is the case.
While debugging, Visual Studio will keep track of every variable in the current context.
Consider the following piece of code:
When the program breaks, the current context is
SomeMethod2
. At this point the developer is unable to check what the value ofj
would be. This is becauseint j
is not a variable in the current context.The actual reason behind OP's described behavior:
So if we change the name of variable
j
toi
inSomeMethod1
, we can suddenly view its "value". Imagine how weird it would get ifi
inSomeMethod2
was a string:When should you know this?
Whenever you have a piece of code where it's not immediately clear what the current context is. I encountered this problem in the following piece of code:
I was debugging
Method 2
but I thought I could view the variables ofMethod 1
as well. But this wasn't the case becauseMethod 1
has its own context.Try to:
Hope that helps.