Tuple Deconstruction
It is possible to deconstruct a Tuple
into variables using the following syntax:
var myTuple = (1, "red", new DateTime(2000, 1, 1));
var (i, c, d) = myTuple;
In a code-golf scenario, you could use this to pass a tuple into a function:
t=>{var(i,c,d)=t;Print(i);Print(c);Print(d);}
Try it online!
A more practical use of this is to decompose a list of tuples and iterate over them using foreach
.
var myTuples = new[] {
(1, "red", new DateTime(2000, 1, 1)),
(2, "blue", new DateTime(2000, 1, 1))
};
foreach (var (i, c, d) in myTuples) {
Print(i);
Print(c);
Print(d);
}
Or in a code-golf scenario:
t=>{foreach(var(i,c,d)in t){Print(i);Print(c);Print(d);}}
Try it online!