Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primary constructors no longer compile in VS2015

Until this very day, I could make use of primary constructors, such as:

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

To be able to do this, in the previous Visual Studio CTP, I had to add this to the csproj-file:

<LangVersion>Experimental</LangVersion> 

Anyhow, this no longer works in the Visual Studio 2015 Preview (with or without LangVersion). Does anyone have any ideas about what could be going on?

like image 244
Matko Avatar asked Nov 13 '14 18:11

Matko


People also ask

How to Generate constructor in Visual Studio 2022?

Place your cursor on the instance. Press Ctrl+. to trigger the Quick Actions and Refactorings menu. Select Generate constructor in <QualifiedName> (with properties).

What is primary constructor in C#?

Basically a Primary Constructor is a feature of C# that was announced with Visual Studio 2014 by which a class or structure can accept parameters in the class definition without a formal constructor declaration.

Which is a code snippet used for inserting a constructor?

Type ctor, and then press the Tab key.


1 Answers

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.

like image 172
Jon Skeet Avatar answered Oct 16 '22 10:10

Jon Skeet