Why does .ToString() on a null string cause a null error, when .ToString() works fine on a nullable int with null value?

前端 未结 8 1298
耶瑟儿~
耶瑟儿~ 2020-11-30 12:19

selectedItem has two fields:

  • int? _cost
  • string _serialNumber

In this example, _cost

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 12:58

    A string is a reference type, but a nullable int is a value type. Here is a Good discussion of the differences http://www.albahari.com/valuevsreftypes.aspx.

提交回复
热议问题