since this is probably a compiler issue
Depends on your definition of "issue". What you see is not unexpected if you are debugging an optimized build. The C# compiler is unlikely to coalesce variable storage (I'm guessing it simply can't), but the JIT compiler, which is what creates the native code that actually executes, certainly can and most likely would.
So, your variable a
, being unused after the assignment to diff
, is having its storage location reused for the variable diff
, rather than allocating a whole new location for it.
Since both variables are using the same location, when you watch the value in the debugger, changing one variable has the effect of changing the other.
For more discussion on debugging optimized builds, see:
Cannot obtain value because it has been optimized away
What is the point of nop in CIL
The second link doesn't really pertain to the "reused variable slot" aspect per se, but Hans' answer does include the sentence "You can still debug a Release build, it is however a pretty confounding experience that makes you doubt your sanity", which IMHO sums up the whole broad topic nicely. :)