<p>I just realized that in some place in my code I have the return statement inside the lock and sometime outside. Which one is the best?</p>

<p>1)</p>

<pre><code>void example()
{
    lock (mutex)
    {
    //...
    }
    return myData;
}
</code></pre>

<p>2)</p>

<pre><code>void example()
{
    lock (mutex)
    {
    //...
    return myData;
    }

}
</code></pre>

<p>Which one should I use?</p>

It doesn't make any difference; they're both translated to the same thing by the compiler.
To clarify, either is effectively translated to something with the following semantics:
```
```
T myData;
Monitor.Enter(mutex)
try
{
    myData= // something
}
finally
{
    Monitor.Exit(mutex);
}

return myData;
```
```