Itโs good as it is. The second condition will not be checked if HasValue false, so it will not throw an exception. It is somehow:
string name = ...; if (name != null && name.Length > 5)
Again, this is fine - you will not get a NullReferenceException if name is null because && is short-circuited.
Similar to || the operator has a short circuit, but vice versa: there, if the left operand is true, the general expression evaluates to true without checking the right operand. For example:
// Treat null as if it were an empty string if (name == null || name.Length == 0)
EDIT: As noted in the comments, this only applies to && and || - this does not apply to and and |, which always evaluate both operands.
Jon skeet
source share