the fact that a type is non-nullable doesn't prevent you from asking if it equals null. Remember that == (and !=) can be overloaded and this means that you could have a struct with == and != overloads that specially treat null.
The is operator, on the other hand, can't be overloaded - so the compiler can and will issue an error when attempting to check if a non-nullable type is null.
If you add if(dt is object) you should be getting true every time, since dt is non-nullable.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
the fact that a type is non-nullable doesn't prevent you from asking if it equals null. Remember that
==
(and!=
) can be overloaded and this means that you could have a struct with==
and!=
overloads that specially treatnull
.The
is
operator, on the other hand, can't be overloaded - so the compiler can and will issue an error when attempting to check if a non-nullable type is null.If you add
if(dt is object)
you should be gettingtrue
every time, sincedt
is non-nullable.