Skip to content
Codewilds

Lesson 34 of 34 · LINQ & Errors

Boss: The Null Wraith of the Archives

Boss battlehard100 XP2 min read

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:

  1. InvalidLogLineException(line) stores the line in Line, with the message Invalid log line: "<line>".
  2. Archive.ParseLine(line) returns the trimmed Bounty, or throws InvalidLogLineException for an invalid line.
  3. Archive.ParseAll(lines) returns the bounties of all valid lines, in order, skipping null, blank and invalid lines.
  4. Archive.CountInvalid(lines) returns how many lines are invalid (null and blank lines are not counted).
  5. Archive.GoldByHero(bounties) returns the total gold of every hero.
  6. Archive.TopHero(bounties) returns the hero with the most gold in total (alphabetically first on a tie), or null if there are no bounties.
  7. Archive.BiggestBounty(bounties, monster) returns the largest gold paid for that monster — the name is matched case-insensitively — or null if 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
Play the 8 free lessons

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 .

Write code ↓
C#+100 XP

Lesson 34 is part of the full course. The first 8 lessons are free.

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
Play the 8 free lessons

Want more than one course?

The All-Access Pass unlocks all 8 courses and every new one we release, for $120 once.