title: Why can't I declare a variable with the same name in different scopes in C#?
body: <p>Not sure if this is because the C# compiler is extra picky, but I try to do this in C#:</p>
  
  <pre><code>public static void Main()
  {
      bool result = true; // some dummy value
      if(result)
      {
          int x = 5;
          Console.WriteLine(x);
      }
  
      int x = 10;
      Console.WriteLine(x);
  }
  </code></pre>
  
  <p>The compiler complains that the variable name "x" is already being used:</p>
  
  <blockquote>
    <p>A local variable named 'x' cannot be declared in this scope because it
    would give a different meaning to 'x', which is already used in a
    'child' scope to denote something else.</p>
  </blockquote>
  
  <p>And I understand that it thinks it's a scope issue, but why does it think that?</p>
  
  <p>If I reproduce the same code in Java, there are no problems.</p>