title: Can I put a return statement inside a lock
body: <p><strong>Dupe:</strong> <a href="https://stackoverflow.com/questions/266681/c-return-statement-in-a-lock-procedure-inside-or-outside">return statement in a lock procedure: inside or outside</a></p>
  
  <p>The title is a little misleading. I know that you can do it, but I'm wondering about the performance implications.</p>
  
  <p>consider these two blocks of code. (no error handling)</p>
  
  <p>This block has the <code>return</code> outside of the lock</p>
  
  <pre><code> public DownloadFile Dequeue()
   {
       DownloadFile toReturn = null;
       lock (QueueModifierLockObject)
       {
           toReturn = queue[0];
           queue.RemoveAt(0);
       }
       return toReturn;
   }
  </code></pre>
  
  <p>This block has the <code>return</code> statement <em>within</em> the lock</p>
  
  <pre><code> public DownloadFile Dequeue()
   {
       lock (QueueModifierLockObject)
       {
           DownloadFile toReturn = queue[0];
           queue.RemoveAt(0);
  
           return toReturn;
       }
   }
  </code></pre>
  
  <p>Is there any difference in the code? I understand that the performance differences (if any) would be minimal, but I am specifically wondering if there would be a difference in the order that the <code>lock</code> gets release.</p>