Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 591 Bytes

GCop169.md

File metadata and controls

24 lines (18 loc) · 591 Bytes

GCop 169

"Remove {NullableObject.HasValue} which is redundant. If {NullableObject.HasValue} is null, then '{rightExpression}' will be false anyway."

Rule description

When you perform comparisons with nullable types, if the value of one of the nullable types is null and the other is not, all comparisons evaluate to false and there is no need to check with HasValue again.

Example

if (myNullableDecimal.HasValue && myNullableDecimal.Value == decimal.Zero)
{
    ...
}

should be 🡻

if (myNullableDecimal == decimal.Zero)
{
    ...
}