Lesson 34 of 34 · LINQ & Errors
Boss: The Null Wraith of the Archives
The Null Wraith blocks the way. Every test you pass deals damage — pass them all to defeat it and claim a loot chest.
At the top of the Citadel lies the Archive, where every bounty ever paid was recorded. Something has been feeding on it: the Null Wraith, a spectre that devours data and leaves holes behind. Lines are torn, numbers are scrambled and whole entries have vanished into null. Rebuild the records from what remains, answer the Archivist's questions — and when the answer truly is nothing, say so with null instead of crashing. Do that, and the Wraith dissolves for good.
Battle plan
Each line of the bounty log looks like this:
Aria;dragon;250
hero ; monster ; gold. Spaces around the parts are allowed. A line is invalid if it does not have exactly three parts, if the hero or monster is empty, or if the gold is not a whole number of at least 0. The Wraith also left null entries and blank lines in the log — those are simply skipped and do not count as invalid.
This fight uses all of Chapter 6:
- a custom exception (
InvalidLogLineException) that carries the broken line; - try/catch to skip bad lines without stopping;
- LINQ to group, sum, sort and filter;
- nullable return types (
string?,int?) for questions without an answer.
Assignment
Bounty(Hero, Monster, Gold) is a record. Complete:
InvalidLogLineException(line)stores the line inLine, with the messageInvalid log line: "<line>".Archive.ParseLine(line)returns the trimmedBounty, or throwsInvalidLogLineExceptionfor an invalid line.Archive.ParseAll(lines)returns the bounties of all valid lines, in order, skippingnull, blank and invalid lines.Archive.CountInvalid(lines)returns how many lines are invalid (nulland blank lines are not counted).Archive.GoldByHero(bounties)returns the total gold of every hero.Archive.TopHero(bounties)returns the hero with the most gold in total (alphabetically first on a tie), ornullif there are no bounties.Archive.BiggestBounty(bounties, monster)returns the largest gold paid for that monster — the name is matched case-insensitively — ornullif the monster never appears.
Premium lesson
Unlock the full Learn C# course
- All 34 lessons, bosses and quizzes — lifetime access
- One payment of $35, no subscription
- Finish within 30 days and claim $10.50 (30%) back
Want more than one course?
The All-Access Pass unlocks all 8 courses and every new one we release, for $120 once.
Keep learning
Need a quick reminder? The C# cheat sheet has every topic of Learn C# on one page.
Lesson last updated on .