【发布时间】:2020-01-28 23:16:54
【问题描述】:
当我创建一个新的控制台应用程序 (.NET Framework 4.8) 并尝试使用 C# 8 的可为空引用类型时,我看到以下内容:
而且,我在构建输出中收到此警告:
warning CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
可以理解,我还没有启用可为空的引用类型。我将以下内容添加到我的 .csproj:
<Nullable>enable</Nullable>
这会使构建警告消失,但 Visual Studio 的 IntelliSense 一直在抱怨。
如何配置 Visual Studio,使其了解我在 .NET Framework 项目中使用可为空的引用类型,而不在任何地方使用 #nullable?
相比之下,如果我创建一个新的 .NET Core 3.0 控制台应用程序,一切都会按预期工作。
【问题讨论】:
-
遗憾的是,C#8 功能仅适用于 Net Core 3。
-
@Rudey 抱歉,看来我弄错了。我尝试使用 C# 8,但直到 Core 3 才对我有用。
-
@Rudey 这是一个 Visual Studio 问题 - Intellisense 是一个 VS 功能。你用的是哪个 VS 版本?
-
这是哪个版本的 Visual Studio?更新了吗?
标签: visual-studio intellisense c#-8.0 nullable-reference-types .net-4.8