c# - Concise way of checking if one of two values is null while the other isn't -
sometimes need verify out of 2 values, 1 is null while other isn't. works:
(a != null && b == null) || (a == null && b != null)
but becomes cluttered when variable names longer, nested properties on object. creating helper function option this, there more concise syntax writing inline?
try this:
(a == null) != (b == null)
note if operator == overriden class, can have problem. following not use operator ==
object.referenceequals(a, null) == object.referenceequals(b, null)
Comments
Post a Comment