This commit is contained in:
Oli Sturm
2022-10-21 13:17:37 +01:00
parent 238814edbb
commit a2d1e4adc2
2 changed files with 7 additions and 2 deletions
+6 -2
View File
@@ -22,12 +22,16 @@
}
static void Main(string[] args) {
// Positional pattern (using a tuple - hence "tuple pattern")
// Important: this works with any deconstructable type!
// This is a tuple, supported since C# 7
(string, string) personInfo = ("Oli", "Sturm");
var (firstName, lastName) = personInfo;
// firstName ist jetzt "Oli" und lastName ist "Sturm"
// Positional pattern (using a tuple - hence "tuple pattern" in this special case)
// Important: this works with any deconstructable type! Example coming up in CS9 sample.
if (personInfo is ("Oli", var olisLastName))
Console.WriteLine($"Found Oli, his last name is {olisLastName}.");
// Nested property patterns:
var customer = new Customer
{