fork download
  1. using static System.Console;
  2.  
  3. public class Person {
  4. public string FirstName { get; set; }
  5. public string MiddleName { get; set; }
  6. public string LastName { get; set; }
  7. public string City { get; set; }
  8. public string State { get; set; }
  9.  
  10. public Person(string fname, string mname, string lname, string cityName, string stateName) {
  11. FirstName = fname;
  12. MiddleName = mname;
  13. LastName = lname;
  14. City = cityName;
  15. State = stateName;
  16. }
  17.  
  18. public void Deconstruct(out string fname, out string lname) {
  19. fname = FirstName;
  20. lname = LastName;
  21. }
  22.  
  23. public void Deconstruct(out string fname, out string mname, out string lname) {
  24. fname = FirstName;
  25. mname = MiddleName;
  26. lname = LastName;
  27. }
  28.  
  29. public void Deconstruct(out string fname, out string lname, out string city, out string state) {
  30. fname = FirstName;
  31. lname = LastName;
  32. city = City;
  33. state = State;
  34. }
  35. }
  36.  
  37. public class Example {
  38. public static void Main() {
  39. var p = new Person("John", "Quincy", "Adams", "Boston", "MA");
  40. var (fName, lName, city, state) = p; //essa sintaxe é de desconstrução chamando o terceiro método
  41. WriteLine($"Hello {fName} {lName} of {city}, {state}!");
  42. var (nome, sobrenome) = p; //aqui chama o primeiro método de desconstrução.
  43. WriteLine($"{nome} {sobrenome}");
  44. var (pnome, _, unome) = p; //aqui chama o segundo método de desconstrução.
  45. WriteLine($"{pnome} {unome}");
  46. }
  47. }
  48.  
  49. //https://pt.stackoverflow.com/q/482769/101
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(40,9): error CS0584: Internal compiler error: Custom deconstruct
prog.cs(41,34): error CS0841: A local variable `fName' cannot be used before it is declared
prog.cs(41,43): error CS0841: A local variable `lName' cannot be used before it is declared
prog.cs(41,58): error CS0841: A local variable `city' cannot be used before it is declared
prog.cs(41,68): error CS0841: A local variable `state' cannot be used before it is declared
prog.cs(42,3): error CS0584: Internal compiler error: Custom deconstruct
prog.cs(43,22): error CS0841: A local variable `nome' cannot be used before it is declared
prog.cs(43,30): error CS0841: A local variable `sobrenome' cannot be used before it is declared
prog.cs(44,3): error CS0584: Internal compiler error: Custom deconstruct
prog.cs(45,22): error CS0841: A local variable `pnome' cannot be used before it is declared
prog.cs(45,31): error CS0841: A local variable `unome' cannot be used before it is declared
Compilation failed: 11 error(s), 0 warnings
stdout
Standard output is empty