This compiles without error or warning, how is this possible?
if (DateTime.Now == null) { }
EDIT:
It’s getting even better:
If I do the same with Decimal, int or a user defined struct, I get a compiler error.
What is the difference?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Why can TimeSpan and Guid Structs be compared to null?
Good explanation in the answer here
Several code-analysis tools (like Resharper) will flag it as “always false” and subsequent code as unreachable.