简体   繁体   English

变量在上下文中不存在,但它是明确定义的

[英]Variable does not exist in context, yet it is clearly defined

In the image below, you can see that I am debugging my code and the variable y1 should be defined. 在下图中,您可以看到我正在调试我的代码,应该定义变量y1 However, I am not getting any exceptions and the variable seems not to exist! 但是,我没有得到任何例外,变量似乎不存在! Why doesn't visual studio recognize my variable? 为什么visual studio不能识别我的变量? I believe there must be a problem with my installation; 我相信我的装置一定有问题; can anyone else confirm? 谁能确认吗?

在此输入图像描述

Ref. 参考。 http://i.imgur.com/RO7oqZ6.gif http://i.imgur.com/RO7oqZ6.gif

The compiler can prove that the variable is never read, so it doesn't even bother to create it since it knows that it is never used. 编译器可以证明该变量永远不会被读取,因此它甚至不会创建它,因为它知道它从未被使用过。 If you alter the code to actually use the variable that optimization won't happen, and you'll be able to observe the variable through the debugger. 如果您改变代码以实际使用变量,那么优化将不会发生,并且您将能够通过调试器观察变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM