Putting It Together: An Extensible Calculator

To recap everything learned about delegates so far, create a calculator that can be extended by plugging in new operators. Although we don’t focus on the UI aspect, take a look at Figure 17.13 to see what I have in mind.

Figure 17.13. An extensible calculator.

image

Besides typical arithmetic operations like add, subtract, multiply, divide, and modulo, four additional programmable function keys are provided. The way the programming is done is something you can dream about, but what’s more interesting is how to create a generic calculator engine in which those custom operations can be plugged.

Let’s try ...

Get C# 4.0 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.