I have a string variable and a string constant. Both should be the same value (I'm testing for equality in a conditional). The 'correct' values of both should be "scl". While debugging, if I put a watch on each, look at them in the 'locals' windows, or hover over them, the value displayed is "sd", which is the value of a different constant in the class (there are many other constants and variables in the class that are displaying values correctly). If I insert开发者_高级运维 a Debug.WriteLine for the variable/constant value in question, (in the same scope as the watch) the output window prints the correct value of each. For the life of me, I can't figure out why this is happening, or how to correct it.
I seemed to have fixed it by changing the value of the constant, running a debugging session, then changing the value back to what it should be. Perhaps this cleared out some kind of debugging cache.
Thanks for the help all!
Is it a lazy loaded property? I've had issues like this in the past where I've done something like this (horribly contrived example, but it will do)
public ClassWithMoo
{
private string moo;
public string Moo
{
get
{
if (String.IsNullOrEmpty(this.moo)) this.moo = "Baa";
return this.moo;
}
set
{
this.moo = value;
}
}
}
public ClassThatUsesMoo
{
ClassWithMoo cow = new ClassWithMoo();
// breakpoint here would show cow.Moo = "Baa"
// This is because the debugger/watch window will instantiate the property!
someCodeHere();
cow.Moo = "Moo";
debug.WriteLine(cow.Moo); // outputs 'Moo' now that it has been set properly
}
精彩评论