Will the C# compiler turn Method1 into
Method2 automatically
No
and skip B() if A() is false?
Yes
In general, the code like
return A(value) && B(value);
Is faster than
if(!A(value)
return false;
if(!B(value)
return false;
Because the first variant can be converted to x86 code that doesn't use jumps.
For instance in code:
private static bool B_1(int value)
{
return value < 5;
}
private static bool B_2(int value)
{
if (value < 5)
return true;
else
return false;
}
For B_1 C# generated a slightly faster x86 code than for B_2.
In this particular situation I would say that it depends on A() and B(). I would run it under profiler to see which is faster.