title: goto vs method in finally block in c#
body: <p>I am particularly aware of <a href="https://msdn.microsoft.com/en-IN/library/zwc8s4fz.aspx" rel="nofollow noreferrer">C# Reference</a>  and have analysed why can't i use goto statement in finally blocks but i wonder when i am trying the same thing with using methods the i am finally able to leave the finally block but according to specification i must not. Isn't the <code>goto moo</code> and <code>static void moo()</code> doing the same act i.e taking me out of finally block?? So why in <strong>first</strong> case it is not working but working smooth in <strong>second</strong> case?</p>
  
  <blockquote>
    <p>It is a compile-time error for a break, continue, or goto statement to transfer control out of a finally block. When a break, continue, or goto statement occurs in a finally block, the target of the statement must be within the same finally block, or otherwise a compile-time error occurs.</p>
  </blockquote>
  
  <p>It is a compile-time error for a return statement to occur in a finally block.</p>
  
  <p>First Case with Goto statement.</p>
  
  <pre><code>static void Main(string[] args)
              {
                  try{}
                  catch (Exception ex){}
                  finally
                  {
                      goto moo;
                  }
              moo:
                  Console.Write("Hello");
              }
  </code></pre>
  
  <p>Second case with Methods : it worked!</p>
  
  <pre><code> static void Main(string[] args)
          {
  
              try{}
              catch{}
              finally
              {
                  moo();
              }
          }
          static void moo()
          {
              int x=2, y=3, a=4, b=7;
              if (x == y)
                  return;
              else
                  a = b;
          }
  </code></pre>
  
  <p>The GOTO statement is generally considered to be a poor programming practice that leads to unwieldy programs. Its use should be avoided.</p>