null
check is redundant when used in combination with is
CS-R1043null
check 82 // CS-R1043: `null` check is redundant when used in combination with `is`.
83 // The condition can be simply written as `f is Foo`.
84 // https://deepsource.io/directory/analyzers/csharp/issues/CS-R1043.
85 if (f != null && f is Foo) 86 {
87
88 }
Since null
is not an instance of any type, there's no reason to chain a null
check and is
operator — a simple is
check would suffice.
if (value != null && value is SomeType)
{
// ...
}
if (value is SomeType)
{
// ...
}