Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. However, I am not getting any exceptions and the variable seems not to exist! Why doesn't visual studio recognize my variable? I believe there must be a problem with my installation; can anyone else confirm?

enter image description here

Ref. https://i.sstatic.net/5Bgu7.gif

like image 566
user1477388 Avatar asked Sep 16 '25 21:09

user1477388


1 Answers

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.

like image 154
Servy Avatar answered Sep 18 '25 10:09

Servy