简体   繁体   中英

Bitwise Or of null check in C#

I was going through the IEqualityComparer Example here I don't understand the need for the second condition with Bitwise Or

if (b2 == null && b1 == null)
   return true;
else if (b1 == null | b2 == null)
   return false;

Why is there a need for such a condition?

The first condition returns true (equal) if both are null.

When you get to the second condition it's already determined that they aren't both null (or else the first condition would have been true.)

So in the second condition if either one is null then that means that only one of them is null. If one is null and the other isn't then they aren't equal.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM