Code inspection: Possible comparison of value type with 'null'
Last modified: 11 February 2024tip
Consider the following piece of code:
While it may not be obvious at first, the T
type can, in fact, be a value type (for example, a struct
or an integer). This would lead to the comparison being ignored altogether, which might not be what the user has intended.
ReSharper does not suggest any quick-fixes here because there is no simple way to check all possible value types of the T
.
One option for resolving this would be to constrain the T
parameter to class types:
However, after such fix you'll have to make sure that all usages of PrintItems<T>()
satisfy the generic constraint.