Are there other scenarios where I need to use one of the following other than what is mentioned?
Nullable.GetValueOrDefault()
: If the value is null, you will get null, otherwise the value.Nullable.Value
: If the value is null, an exception will be thrown.Nullable<>.HasValue
: Returns true or false.Nullable<> != null
Same as above.
I was a bit confused because I have seen codes on GitHub check the HasValue
or != null
then return the value if true, otherwise return null. I would rather just use the first. Is there any side-effect or something that I am missing?