Let the object answerintermediate
A switch on a type must be edited every time a type is added, and there is always more than one of them; asking the object instead means a type invented tomorrow works in code written today.
Given the registered payment channels, return the cheapest one that can take the amount: the first one on a tie, and null when none can.
AssumesThe wrong containerThis stage uses a List as the vehicle, not the lesson. Choosing the right collection is taught there.
A foreach over the base type with no type checks, decimal money, limits as conditions, and both amounts traced.
Published in full, before you start — every point is one of these and there is nothing else.
A switch on a type must be edited every time a type is added, and there is always more than one of them; asking the object instead means a type invented tomorrow works in code written today.
A List makes you walk every item to find one; a Dictionary jumps straight to it — picking wrong turns a fast page into a slow one as soon as real data arrives.
A date, a price, a flag — each is stored as numbers, and integer division and remainder are how you take a number apart; money needs decimal because binary floating point cannot hold 0.10 exactly.
Network calls fail. Code that assumes they succeed turns a slow connection into a blank screen with no explanation.