IMO when checking if a string is "set":
- Simply using
bla is null
/bla is not null
is idealbla == null
/bla != null
is functionally equivalent for strings. For other types, "==" and "!=" could theoretically have a slow or incorrect override.is null
/is not null
is generally preferable since it ignores overrides.
string.IsNullOrWhiteSpace(bla)
is generally wrong- In some contexts,
string.IsNullOrEmpty()
does make sense
In most code that accepts input from other code (i.e. not a human), it is more elegant only use null
to indicate the absence of a value, and not empty strings or whitespace:
- That's literally what
null
means