Possible Duplicate:
Which is preferred: Nullable<>.HasValue or Nullable<> == null?
I'm working in a codebase which uses both of the following forms for "safely" getting values out of Nullable types. For example, if foo
is a Nullable (int?):
if (foo != null) {
value = (int)foo;
}
if (foo.HasValue) {
value = foo.Value;
}
I prefer the second form, but is there any particular context which might make the first (or the second, for that matter) certainly preferred over the other?