你可以有多个枚举值相同的整数? [英] Can you have multiple enum values for the same integer?

查看:200
本文介绍了你可以有多个枚举值相同的整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET 可以有多个枚举值相同的整数?

如:

 公开枚举PersonGender
    {
        未知= 0,
        雄性= 1,
        女= 2,
        雌雄同体= 3,
        不确定= 3,
        NonStated = 9,
        InadequatelyDescribed = 9
    }
 

解决方案

在C#中,这是允许的,具体根据的 C#语言Specication ,第4版。

1.10枚举没有提到的可能性,但后来在第 14枚举,我们看到(在 14.3 ):


多个枚举成员可以共享同一个关联值。这个例子

 枚举颜色{
   红,
   绿色,
   蓝,
   最大=蓝
}
 

显示了一个枚举,其中两个枚举成员 - 最大 - 具有相同的关联值

In .NET can you have multiple enum values for the same integer?

eg.

public enum PersonGender
    {
        Unknown = 0,
        Male = 1,
        Female = 2,
        Intersex = 3,
        Indeterminate = 3,
        NonStated = 9,
        InadequatelyDescribed = 9
    }

解决方案

In C#, this is allowed, as per the C# Language Specication, version 4.

Section 1.10 Enums doesn't mention the possibility but later on in section 14 Enums, we see (in 14.3):


Multiple enum members may share the same associated value. The example

enum Color {
   Red,
   Green,
   Blue,
   Max = Blue
}

shows an enum in which two enum members - Blue and Max - have the same associated value.

这篇关于你可以有多个枚举值相同的整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆