Why does a `null` Nullable<T> have a hash code?

asked8 years ago
last updated8 years ago
viewed4.4k times
Up Vote39Down Vote

Bit of a weird question...

But can anyone give me a justification for why this would be expected behaviour?

This just seems totally odd to me....

//Makes perfect sense
object o = null;
o.GetHashCode().Dump();

NullReferenceException: Object reference not set to an instance of an object.

//Seems very odd
int? i = null;
i.GetHashCode().Dump();

0

This obviously means:

int? zero = 0;
int? argh = null;

zero.GetHashCode() == argh.GetHashCode(); //true