多个枚举和“切换”操作符

时间:2013-03-29 20:20:35

标签: enums switch-statement

我有以下代码:

        var statusCode = response.StatusCode;
        switch (statusCode)
        {
            case ObexStatusCode.Accepted:
                break;
            case ObexStatusCode.BadGateway:
                break;
            case ObexStatusCode.BadRequest:
                throw new BadRequestException();
                break;
            case ObexStatusCode.Conflict:
                throw new ConflictException();
                break;
            case ObexStatusCode.Continue:
                break;
            case ObexStatusCode.Created:
                break;
            case ObexStatusCode.DatabaseFull:
                break;
        }

如果statusCode只有一个值,它可以正常工作。但有时它可以有2个值。据我所知,我可以这样写:

        if ((statusCode & ObexStatusCode.Accepted) == ObexStatusCode.Accepted)
        {
        }

但如何使用SWITCH进行操作?感谢

0 个答案:

没有答案