Programming against an enum in a switch statement, is this your way to do?

前端 未结 12 2274
青春惊慌失措
青春惊慌失措 2020-12-24 09:15

Look at the code snippet:

This is what I normally do when coding against an enum. I have a default escape with an InvalidOperationException (I do not use ArgumentExc

12条回答
  •  温柔的废话
    2020-12-24 10:14

    I'm a C programmer, not C#, but when I have something like this, I have my compiler set to warn me if not all enum cases are handled in the switch. After setting that (and setting warnings-as-errors), I don't bother with runtime checks for things that can be caught at compile time.

    Can this be done in C#?

提交回复
热议问题