Boxing/Unboxing and Nullable?

后端 未结 3 1606
遇见更好的自我
遇见更好的自我 2021-01-05 05:22

I understand that boxing and unboxing is about casting (real type to object... object to real type). But I do not understand what the MSDN say about it with the Nullable. He

3条回答
  •  时光说笑
    2021-01-05 05:50

    What it's saying is that if you do:

    int? x = 5;
    object y = x; // Boxing
    

    You end up with a boxed int, not a boxed Nullable. Similarly if you do:

    int? x = null; // Same as new Nullable() - HasValue = false;
    object y = x; // Boxing
    

    Then y ends up as a null reference.

提交回复
热议问题