Variable type ending with ?

前端 未结 7 2139
别跟我提以往
别跟我提以往 2021-01-04 11:08

What does ? mean:

public bool? Verbose { get; set; }

When applied to string?, there is an error:

7条回答
  •  灰色年华
    2021-01-04 11:55

    bool? is a shorthand notation for Nullable. In general, the documentation states:

    The syntax T? is shorthand for Nullable, where T is a value type. The two forms are interchangeable

    Since string is not a value type (it's a reference type), you cannot use it as the generic parameter to Nullable.

提交回复
热议问题