4

Microsoft's example of Expression Bodied Constructors (https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/expression-bodied-members) shows the following, which works obviously:

public class Location
{
     private string locationName;

     public Location(string name) => locationName = name;
}

But when I attempt the following, no go:

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);
}
Tiffany
  • 41
  • 2
  • This is the answer: https://stackoverflow.com/questions/38382971/predefined-type-system-valuetuple%c2%b42%c2%b4-is-not-defined-or-imported/44232383 – Tiffany Jul 20 '17 at 17:42

0 Answers0