Skip to main content

Practice ยท 2 of 4

Operator dispatch table

CHALLENGE
Difficulty: beginner+25 XP

Implement static int Eval(char op, int a, int b) using a dispatch table of Func<int, int, int> (dictionary from char to function): '+' 'โˆ’' '*' '/' (integer division). Unknown operator โ†’ ArgumentException. Division by zero propagates naturally.

Back to lesson: Practice: Delegates workout