Which “C# Experimental language feature” is this?

て烟熏妆下的殇ゞ 提交于 2019-12-04 03:03:36

问题


In the example below, Resharper shows "C# Experimental language feature" tooltip on the first curly bracket. I've checked the new features of C# 6.0 but didn't come across a similar one. What is the referred experimental feature?

 class Class1
 {
     { // <= C# Experimental language feature
     }
 }

Note: It is an error for .Net Framework 4.5 compiler.

"Invalid token '{' in class, struct, or interface member declaration"


回答1:


This was for Primary Constructors, a feature which has now been cut from C#6.




回答2:


On November 12, 2014 Microsoft announced the release of Visual Studio 2015 on the day of Visual Studio Connect() from New York, USA where they announced many new features as well as enhancements with C# 6.0. So we should understand that a Primary Constructor is not applicable with C# 6.0 but we can do the same thing using Auto Implemented Properties Initializers.

Basically a Primary Constructor is a feature of C# that was announced with Visual Studio 2014. But now it has been removed from Visual Studio 2015 Preview. So in C# 6.0 it's not possible to use a primary constructor.




回答3:


You can still use this if you click on your project, and go to the Properties pane and select C# Language Level to Experimental.



来源:https://stackoverflow.com/questions/30122228/which-c-experimental-language-feature-is-this

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!