There are three unreachable statements in your code, first two are the break statements and the last one int he last line "return true" is also unreachable, I dont know whether C# compiler detects that or not, but logically there is no way last return statement will also be reached.
There are multiple ways to solve this issue,
- Store a temp variable, called bool retVal, keep retVal and break your switch case and at the end of function return retVal.
- If you return value before break, break statement is useless.
Better Design Way
If you return values within switch cases, it may be difficult to analyze your code later on by you or someone else, usually it is better to keep a return value temp variable and return it at end of function, that becomes easier to debug and understand the code for new coder.
Switch can be complicated, and more returns within switch may not have better control, if you want to implement logging, debugging, returns from cases could be complicated. And it becomes way to difficult browsing the logic flow graphs.
So it is better to avoid return altogather from case, but still it depends on situtations as well, one needs to make an intelligent decision here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…