Unreachable code detected in case statement

前端 未结 14 2467
终归单人心
终归单人心 2020-12-06 16:37

I have a code:

    protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
    {
        switch (keyData)
        {
            case Keys.Alt|Ke         


        
14条回答
  •  庸人自扰
    2020-12-06 16:49

    Bitter experience has taught me to always include break statements unless you really mean to fallthrough to the next statement and even then, comment it. Otherwise a function could behave wildly differently because another developer changed something late on a Friday afternoon and didn't see the missing break.

    If the function - however large - conforms to the same if...return...else....return structure throughout, you could define a return code variable at the start of the function. Then assign it in your case statement and return it at the end, whatever value it turns out to be.

提交回复
热议问题