Which way is better practice: return a value from a method inside an using statement or declare a variable before, set it inside and return it after?
public int Foo()
{
using(..)
{
return bar;
}
}
or
public int Foo()
{
var b = null;
using(..)
{
b = bar;
}
return b;
}
I prefer the first example. Fewer variables, fewer lines of code, easier to follow, easier to maintain…