3 ms·
I like the look of the new tuple syntax (although I would call it multiple return values). From the article: (int sum, int count) Tally(object[] values)
by kristianp 10y ago
I like the look of the new tuple syntax (although I would call it multiple return values). From the article:
(int sum, int count) Tally(object[] values)
{
var r = (s: 0, c: 0);
foreach (var v in values)
{
switch(v)
{
case int i:
r = (r.s + i, r.c + 1);
break;
case object[] l:
var n = Tally(l);
r = (r.s + n.sum, r.c + n.count);
break;
}
}
return r;
}
object[] numbers = { 0b1, 0b10, 0b100, new object[] { 0b100, 0b1_0000 }, 0b10_0000 };
var t = Tally(numbers);
WriteLine($"Sum: {t.sum}, count: {t.count}");