我只是在看PlatformNotSupportedException
类的定义时碰到的。
string? message
是什么意思。就我而言,?
是Nullable<>
的简写,但是Nullable<>
仅适用于struct,并且string
和Exception
是类。
我的最佳猜测是它的一个可选参数,如string message = null
声明,如果是这样,为什么不只显示它和默认值呢?
public PlatformNotSupportedException(string? message, Exception? inner);
这是声明可空引用类型的一种方法。 The syntax to expect NULL
in C# 8:
首先,需要一种语法来区分何时引用类型应为null,否则不应为null。明显的允许为null的语法使用?作为可为空的声明用于值类型和引用类型。通过支持引用类型,开发人员可以选择使用null,例如:
NULL
此外,我们可以声明string? text = null;
:
non-nullable reference type