コード例 #1
0
        public void CS0152ERR_DuplicateCaseLabel_SwitchInEnum()
        {
            var source =
                @"
class c1
{
    public enum Suits
    {
        ValueA,
        ValueB,
        ValueC,
    }
    public void main()
    {
        Suits s = Suits.ValueA;
        switch (s)
        {
            case Suits.ValueA:
                break;
            case Suits.ValueB:
                break;
            case Suits.ValueC:
                break;
            default:
                break;
        }
    }
}
";
            var comp = CreateStandardCompilation(source);

            DiagnosticsUtils.VerifyErrorCodes(comp.GetDiagnostics());
            source =
                @"
class c1
{
    public enum Suits
    {
        ValueA = 2,
        ValueB,
        ValueC = 2,
    }
    public void main()
    {
        Suits s = Suits.ValueA;
        switch (s)
        {
            case Suits.ValueA:
                break;
            case Suits.ValueB:
                break;
            case Suits.ValueC:
                break;
            default:
                break;
        }
    }
}
";
            comp = CreateStandardCompilation(source);
            DiagnosticsUtils.VerifyErrorCodesNoLineColumn(comp.GetDiagnostics(), new ErrorDescription {
                Code = (int)ErrorCode.ERR_DuplicateCaseLabel
            });
        }