Is there any difference between type? and Nullable?

前端 未结 9 1206
礼貌的吻别
礼貌的吻别 2020-12-15 15:53

In C# are the nullable primitive types (i.e. bool?) just aliases for their corresponding Nullable type or is there a difference between th

9条回答
  •  暖寄归人
    2020-12-15 16:23

    I'm surprised nobody went to the source (the C# spec) yet. From §4.1.10 Nullable types:

    A nullable type is written T?, where T is the underlying type. This syntax is shorthand for System.Nullable, and the two forms can be used interchangeably.

    So, no, there isn't any difference between the two forms. (Assuming you don't have any other type called Nullable in any of the namespaces you use.)

提交回复
热议问题