Nullable DateTime with HasValue check Follow
Please take a look at the underneath code:
1. DateTime? startDate = SomeMethod();
2. if (startDate.HasValue)
3. {
4. DoSomething();
5. }
ReSharper says with constructions like this: "Expression is always true" for line 2. Why is this? Looks like a bug to me.
Please sign in to leave a comment.
FWIW, code below works fine with 5.1.1753 (no "is always true" warning).
Hello Marino,
I couldn't reproduce this behavior either. Could you please attach a small
sample solution demonstrating this problem? Thank you!
Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
Are you sure SomeMethod() returns "DateTime?"? If it returns DateTime only the result will never be null and Resharper is correct.
I guess this was the thing that went wrong.
(Sorry for the late(!) reply, apparently I don't get mail if people reply. Shall configure immediately ;) )