刚刚下载了VS2019并创建了一个控制台应用程序以尝试新的C#8空引用类型。将项目切换为使用lang ver C#8进行构建(当前显示为beta)
然后,以下代码将产生警告。
class Program
{
static void Main(string[] args)
{
string? message = "Hello World";
string message2 = null;
Console.WriteLine(message);
Console.WriteLine(message2);
// The annotation for nullable reference types should only be used in code within a '#nullable' context
}
}
Run Code Online (Sandbox Code Playgroud)
这到底是什么意思?