title: Why doesn't my C# compiler (Visual Studio) let me do this with a try block?
body: <p>I have many scenarios during my development where I want to do something such as</p>
  
  <pre><code>try 
  { 
      long presult = EvalInner(eqtn,new Tuple&lt;int, int&gt;(++begidx,curidx-1),eqtnArgs); 
  }
  catch ( Exception e ) 
  { 
      throw e; 
  }
  result = evalNewResult(result,lastop,presult,ref negateNextNum,ref negateNextOp); 
  // ...
  return presult;
  </code></pre>
  
  <p>but then my compiler flags the <code>presult</code> on the line</p>
  
  <pre><code>result = evalNewResult(result,lastop,presult,ref negateNextNum,ref negateNextOp); 
  </code></pre>
  
  <p>saying </p>
  
  <blockquote>
    <p>The name 'presult' does not exist in the current context</p>
  </blockquote>
  
  <p>If it were smart, it would understand that <code>presult</code> is either initialized in the <code>try</code> block, or  the procedure is exited before <code>presult</code> is ever used. </p>
  
  <p><strong>Possible workarounds</strong> (none of them good):</p>
  
  <ol>
  <li>Declare <code>long presult;</code> right before the <code>try</code> statement. This makes the compiler mad because it wrongly thinks there's a possibility of returning an unintialized variable.</li>
  <li>Initialize it with <code>long presult = default(long)</code>. This works, but it's bad practice because someone reading the code doesn't know whether intializing it to the default value is to work around the problem described in 1. or is because the value <code>presult</code> because set to the default <code>long</code> has some real meaning in the context of the program.</li>
  <li>Initialize it with <code>long? presult = null</code>. This is semantically better because it's clear that it means "presult is meant to have no value at this point" whereas in 2. the reader has to figure out that presult has a meaningless value. The problem here is that, not only does it take extra memory to <code>null</code>ify a value, but I then have to change the function <code>EvalInner</code> to return a <code>long?</code> and this results in a chain of needing to change many more <code>long</code>s to <code>long?</code>s and my program ends up splattered with <code>null</code>ified variables; it's a complete mess of question marks haha.</li>
  </ol>
  
  <p>Anyways, how should I be handling a case like this?</p>