How does a Nullable type work behind the scenes?

后端 未结 4 1937
一个人的身影
一个人的身影 2020-12-15 08:41

I\'m curious to know how the Nullable type works behind the scenes. Is it creating a new object(objects can be assigned null) with a possible value of null?

In the

4条回答
  •  春和景丽
    2020-12-15 09:28

    Nullable is implemented as a struct that overrides Equals() to behave as null if HasValue is false. There is an implicit conversion from T to T?, and an explicit conversion in the other direction which throws if !HasValue.

提交回复
热议问题