Microsoft的Expression Bodied Constructors(https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/expression-bodied-members)示例显示以下内容,显然有效:
public class Location
{
private string locationName;
public Location(string name) => locationName = name;
}
但是当我尝试以下内容时,不要去:
public class Location
{
private string locationName;
private string locationCountry;
//but what about two variables?
// (the below code does not work, I get "Error CS8179 Predefinedtype 'System.ValueTuple`2' is not defined or imported)
public Location(string ln, string lc) => (locationName, locationCountry) = (ln, ld);
}