VS2015中不再编译主构造函数

直到今天,我还可以使用主构造函数,例如:

public class Test(string text)
{
private string mText = text;
}

为了能够做到这一点,在上一个 Visual Studio CTP 中,我必须将它添加到 csproj-file:

<LangVersion>Experimental</LangVersion>

无论如何,这在 VisualStudio2015预览版(带或不带 LangVersion)中不再有效。有人知道会发生什么吗?

13699 次浏览

Does anyone have any ideas about what could be going on?

Yup - primary constructors have been removed from the plans for C# 6. They may well make an appearance in some form in a later version, but they're not in C# 6 any more.

See the "Changes to the language feature set" post from the team for more details.