Variable in child scope preventing definition of variable in parent
<p>Today I discovered a, presumably, "feature" of <a href="/questions/tagged/c%23" class="post-tag" title="show questions tagged &#39;c#&#39;" rel="tag">c#</a>:</p>

<blockquote>
  <p>error CS0136: A local variable named <code>foo</code> cannot be declared in this scope because it would give a different meaning to <code>foo</code>, which is already used in a <code>child</code> scope to denote something else</p>
</blockquote>

<p>Which can simply be reproduced by trying to compile this snippet:</p>

<pre><code>if (false) {
    int foo = 42;
}
int foo = 1337;
</code></pre>

<p>Why can't I define <code>foo</code> in the parent scope? The <code>foo</code> from the child scope is not visible in the parent scope, nor would it be still allocated, it's therefore absolutely legal in any proper language. What did I miss? What is the reasoning behind this? </p>