将 Asp.Net Core 3.1 应用程序升级到 .Net 5 后,某些 C# 9 功能不可用 [英] Some C# 9 features not available after upgrading Asp.Net Core 3.1 app to .Net 5

查看:23
本文介绍了将 Asp.Net Core 3.1 应用程序升级到 .Net 5 后,某些 C# 9 功能不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过将相应的 *.csproj 文件修改为以下内容,我已将 Asp.Net Core 3.1 (MVC) 升级到 .Net 5:

I've upgraded an Asp.Net Core 3.1 (MVC) to .Net 5 by modifying the corresponding *.csproj file to this:

<TargetFramework>net5.0</TargetFramework>
<LangVersion>9.0</LangVersion>

现在我可以使用 C# 9 目标打字功能...

Now I can use the C# 9 target typing feature...

string s = new('c', 3); // compiles fine

...但我无法创建 记录:

...but I can't create a record class:

public data class User
{
  // IDE1007 The name 'data' does not exist in the current context. 
}

我在这里遗漏了什么吗?

Am I missing something here?

推荐答案

根据 记录类型规范,你应该使用public record User语法.

According to record type specs, you should use public record User syntax.

最好查看最终规格而不是带有介绍的博客文章,因为有些内容已更改.

It's better to look at final specs rather then blog post with introduction, since some things were changed.

您还可以参考 GitHub 中的 csharplang repo 以查看最新的规范、设计会议和提案.对于特定的记录功能,最初的问题#39 可能是用于跟踪最近的更新和规格

You can also refer to csharplang repo in GitHub to check the most recent specs, design meetings and proposals. For particular Records feature the initial issue #39 might be used to track the most recent updates and specs

这篇关于将 Asp.Net Core 3.1 应用程序升级到 .Net 5 后,某些 C# 9 功能不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆