what if I would have something like this:
if (data == null || (data != null && (data.Count() != 3 || data.IsNotCorrect()))
{
//error...
}
The data == null and then || (data != null) part is somehow ugly. Is that how to solve this problem in c#?
Edit:
Sorry! Changed data.IsCorrect() to data.IsNotCorrect()
The right side of
||gets only evaluated if the left side isn’t true (||is short-circuiting)Quoted from
||Operator (C# Reference) (MSDN)Apply that to your expression:
This means when
data != nullis reached,datais guaranteed to be different fromnull, and thusdata != nullis guaranteed to be true, and you can leave it out.Thus your expression is equivalent to: