title: How to prevent C# compiler/CLR from optimizing away unused variables in DEBUG builds?
body: <p>While debugging I tried to save intermediate results of a calculation to a variable so that when a breakpoint condition is met I could check that value. However C# compiler (or CLR) optimized away that variable as unused. I solved the problem by making the variable a public field of the class, however I'd like to know if there is a straightforward solution to this problem.</p>
  
  <p>"Optimize code" checkbox is unchecked. The build configuration is Debug.</p>
  
  <p>Edit: Found that it only affects some unused variables in iterators that would normally end up as fields in the automatically generated iterator class; unused variables that are scoped within blocks not containing yield statements are retained.</p>