38 public static string Run(
string[] args) {
39 if (args.Length != 3) {
40 throw new ArgumentException($
"Expected 3 arguments (operation, a, b) but got {args.Length}. {UsageText}");
43 string operation = args[0].Trim().ToLowerInvariant();
45 if (!
int.TryParse(args[1], out
int a)) {
46 throw new ArgumentException($
"'{args[1]}' is not a valid 32-bit integer for <a>. {UsageText}");
49 if (!
int.TryParse(args[2], out
int b)) {
50 throw new ArgumentException($
"'{args[2]}' is not a valid 32-bit integer for <b>. {UsageText}");
55 int result = operation
switch {
56 "add" => calculator.Add(a, b),
57 "subtract" => calculator.Subtract(a, b),
58 "multiply" => calculator.Multiply(a, b),
59 "divide" => calculator.Divide(a, b),
60 _ =>
throw new ArgumentException($
"Unknown operation '{args[0]}'. {UsageText}"),
63 return $
"{a} {operation} {b} = {result}";