Unreachable code detected in case statement

Posted by alex on Stack Overflow See other posts from Stack Overflow or by alex
Published on 2010-04-15T08:13:08Z Indexed on 2010/04/15 8:33 UTC
Read the original article Hit count: 219

Filed under:

I have a code:

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

                if (this._condition1)
                {
                    return true;
                }
                else
                {
                    return base.ProcessCmdKey(ref msg, keyData);
                }

                break;

            case Keys.Control |Keys.U:

                if (this._condition2)
                {
                    return true;
                }
                else
                {
                    return base.ProcessCmdKey(ref msg, keyData);
                }

                break;

            default:

                return base.ProcessCmdKey(ref msg, keyData);
        }

        return true;

It gives me "unreachable code detected" warning on breaks.

Is it good practice not to use break operator here ? I don't want to turn off "unreachable code detected" warning.

PS: There are many case in my ProcessCmdKey method.

© Stack Overflow or respective owner

Related posts about c#