I am setting the visibility of a button and I have code like
btnReset.Visible |= newCondition();
What I noticed is |=
is not short circuited, and ||=
does not exist. Granted I can rewrite the statement as
btnReset.Visible = btnReset.Visible || newCondition();
But I was just curious if there was a short hand short circuit operator?
Below is test code to verify that |=
is not short circuit
static void Main(string[] args)
{
bool firstValue = true;
// Short Circuit
bool secondValue = firstValue || CallThisFunction();
// Full Evaluation
bool thirdValue = firstValue | CallThisFunction();
// Full Evaluation
secondValue |= CallThisFunction();
}
private static bool CallThisFunction()
{
return true;
}