[英]What does this mean 'string? message'
我刚刚在查看PlatformNotSupportedException
类的定义时遇到了这个问题。
什么是string? message
string? message
意思。 就我而言是?
是Nullable<>
简写,但Nullable<>
只能应用于结构体, string
和Exception
是类。
我最好的猜测是它的可选参数声明为string message = null
,如果是这样,为什么不只显示它和默认值?
public PlatformNotSupportedException(string? message, Exception? inner);
它是一种声明可空引用类型的方法。 在 C# 8 中期望NULL
的语法:
首先,需要有一种语法来区分引用类型何时应该期望为空,何时不应该期望。 允许 null 的明显语法是使用 ? 作为可空声明——值类型和引用类型。 通过包含对引用类型的支持,开发人员可以选择加入 null,例如:
string? text = null;
此外,我们可以声明不可为空的引用类型:
string! text = "It is non nullable"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.