What is the difference between Nullable<T>.HasValue or Nullable<T> != null?
.net, c#, null, nullable
Solution
The compiler replaces `null` comparisons with a call to `HasValue`, so there is no real difference. Just do whichever is more readable/makes more sense to you and your colleagues.
Problem
I always used `Nullable<>.HasValue` because I liked the semantics. However, recently I was working on someone else's existing codebase where they used `Nullable<> != null` exclusively instead. Is there a reason to use one over the other, or is it purely preference? ``` int? a; if (a.HasValue) // ... ``` vs. ``` int? b; if (b != null) // ... ```