Skip to main content

Practice ยท 2 of 2

Deconstruct the Ledger

CHALLENGE
Difficulty: intermediate+25 XP

Work with tuples and deconstruction: ``csharp /* Splits entries into (income, expense) where expense is stored as positive numbers to subtract. Returns the pair. */ static (int Income, int Expense) Split(int[] signedEntries); /* Finds the earliest first-max: value of the first element that equals the max, and its zero-based index. Empty -> (0, -1). */ static (int Value, int Index) FirstMax(int[] values); /* A record with a Deconstruct(int Whole, int Remainder) โ€” division by a fixed divisor 10: Whole = n / 10, Remainder = n % 10. */ sealed record Split10(int N) { public void Deconstruct(out int whole, out int remainder); } /* The test deconstructs: var (w, r) = new Split10(47); */ ``

Back to lesson: Practice: Pattern Gym