In a previous blog post, I demonstrated how Java’ enums that
contain one or more values/objects can be emulated with C#. One thing
bothered me, though: the
switch statement and how inconvenient it
was to determine the proper type. Worst of all, it was not type-safe.
In my simple example, it was easy because I was using strings. Imagine
your fake-enum does not contain a string to quickly identify the
Well, there is a prettier workaround – and it involves an actual
enum. I was thinking about how the same could be done in C++ and in
C++, you can have type conversion operators. Then I searched if such a
feature also exists in C#, and sure enough, it does.