Consider this code:
public int DownloadSoundFile()
{
using (var x= new X())
{
return x.Value;
}
}
and this code:
public int DownloadSoundFile()
{
if (x!=null)
{
return x.Value;
}
}
The first code doesn't give us any compile time errors but in the second code we get this error:
not all code paths return a value
This means we should return a value outside of the if
scope.
Why do we have to return a value outside of the if
scope but don't need to return a value outside of the using
scope?