What is the purpose of CS0161 when switching over an enum and how to work around it?
- by Danvil
Consider the following example of a simple enum and a switch over all possible enum values.
enum State { Alpha, Beta, Gamma }
State state = ...;
switch(state) {
case Alpha: ... break;
case Beta: ... break;
case Gamma: ... break;
}
Now I get error CS0161: not all code paths return a value.
This seems rather pointless to me, because I would expect that other cases are not possible. So what is the purpose of this error, and how would one work around this in the most elegant way?