Dav*_*cía 4 c# .net-core c#-8.0 .net-core-3.1
我正在按照教程学习使用 .Net Core 3.1 的 c# 版本 8 的新功能
我正在使用最新版本的 Visual Studio 2019。在进行一些练习时,我喜欢下一个代码中的错误
主题:目标类型的新表达
Dictionary<string, List<int>> field = new Dictionary<string, List<int>>();
Dictionary<string, List<int>> field = new(); //this throws the error "requires (), [], or {} after type requires (), [], or {} after type"
Run Code Online (Sandbox Code Playgroud)
我错过了什么?我也尝试添加到项目中
<LangVersion>8.0</LangVersion>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
尽管您可以在任何在线教程中找到语法,但您使用的语法无效。目标类型new最初计划在 C# 8.0 中使用,但最终并未最终确定。
现在(2020-05-10)它被标记为“9.0 Candidate ”里程碑,这意味着它也可能不会成为下一次迭代的一部分。请参阅此 github 提案/问题。
话虽这么说,您可以通过选择“C# Next: Target-typed new (9 Mar 2020)”分支在SharpLab上尝试该功能。
| 归档时间: |
|
| 查看次数: |
18184 次 |
| 最近记录: |