Code inspection: Use null check instead of a type check succeeding on any not-null value
Last modified: 29 May 2024tip
The is operator in C# returns false
in two cases:
This inspection reports cases when the left side of is
is always assignable to the tested type. In such cases, is
will evaluate to false
only when the left side is null
. Therefore, it is suggested to replace the type check with a null check, which will preserve the logic but make readers of the code understand what is actually being tested.
Note that a type check, rather than a null check, may have been the intended condition. If this is the case, you should review your code to determine the underlying issue.