mardi 27 janvier 2015

Why can't we use expression-bodied constructors?


Vote count:

1




Using the new Expression-Bodied Members feature in C# 6.0, we can take a method like this:



public void Open()
{
Console.WriteLine("Opened");
}


...and change it to a simple expression with equivalent functionality:



public void Open() => Console.WriteLine("Opened");


This is not true for constructors, however. Code such as this doesn't compile:



private DbManager() => Console.WriteLine("ctor");


Nor does this:



private DbManager() => {}


Is there any reason why constructors cannot benefit from the expression-bodied members feature, and must be declared the traditional way?



asked 2 mins ago

Gigi

3,286






Why can't we use expression-bodied constructors?

Aucun commentaire:

Enregistrer un commentaire