为什么我的 VS2008 手表显示的值不正确?

发布于 2024-09-07 00:05:18 字数 246 浏览 10 评论 0原文

我有一个字符串变量和一个字符串常量。两者应该是相同的值(我正在测试条件中的相等性)。两者的“正确”值应该是“scl”。在调试时,如果我在每个上放一个手表,在“本地”窗口中查看它们,或将鼠标悬停在它们上,则显示的值是“sd”,这是类中不同常量的值(还有许多其他常量)类中正确显示值的常量和变量)。如果我为有问题的变量/常量值插入 Debug.WriteLine(在与手表相同的范围内),输出窗口将打印每个值的正确值。对于我的一生,我无法弄清楚为什么会发生这种情况,或者如何纠正它。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〃安静 2024-09-14 00:05:18

我似乎通过更改常量的值,运行调试会话,然后将值更改回应有的值来修复它。也许这清除了某种调试缓存。

感谢大家的帮助!

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!

甜扑 2024-09-14 00:05:18

它是一个延迟加载的属性吗?我过去遇到过这样的问题,我做过这样的事情(这是一个非常人为的例子,但它会做)

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
}

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
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文