class Program
{
private static bool _ret = true;
static void Main()
{
_ret &= Method();
Console.WriteLine(_ret);
Console.Read();
}
private static bool Method()
{
_ret &= false;
return true;
}
}
We came across this issue in a larger application we are developing and was wondering if it was expected functionality? This is written in c# with Visual Studio 2010
As explained by Eric Lippert in his blog post “Precedence vs Associativity vs Order”,
So in your case, it evaluates _ret prior to calling Method(), and the fact that _ret changes inside Method() does not affect the outer call.
See: http://blogs.msdn.com/b/ericlippert/archive/2008/05/23/precedence-vs-associativity-vs-order.aspx