Java using enum with switch statement

The part you’re missing is converting from the integer to the type-safe enum. Java will not do it automatically. There’s a couple of ways you can go about this: Use a list of static final ints rather than a type-safe enum and switch on the int value you receive (this is the pre-Java 5 approach) … Read more

error: switch quantity not an integer

In switch, the expression must be of “an integral type or of a class type for which there is an unambiguous conversion to integral type” (quoting VS2008 docs). A string class doesn’t have “unambiguous conversion to integral type”, like a char does. As a work-around: Create a map<string, int> and switch on the value of the map: switch(command_map[command]) ` Do a set of if/else instead of … Read more

C# switch on type

See gjvdkamp’s answer; this feature now exists in C# I usually use a dictionary of types and delegates. It’s a little less flexible as you can’t fall through cases, continue etc. But I rarely do so anyway.