Possible compare of value type with null

Skip to end of metadata
Go to start of metadata

Consider the following piece of code:

While it may not be obvious at first, the T type can, in fact, be a value type (e.g., a struct or an integer). This would lead to the comparison being ignored altogether, which might not be what the user has intended.

One option for resolving this would be to constrain the T parameter to class types:

The other option would be to change the comparison value from null to the default value for the particular type:

Labels:
None
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.