同一个整数可以有多个枚举值吗? [英] Can you have multiple enum values for the same integer?
本文介绍了同一个整数可以有多个枚举值吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 .NET
中,您可以为同一个整数多个枚举
值?
In .NET
can you have multiple enum
values for the same integer?
例如。
public enum PersonGender
{
Unknown = 0,
Male = 1,
Female = 2,
Intersex = 3,
Indeterminate = 3,
NonStated = 9,
InadequatelyDescribed = 9
}
推荐答案
在C#中,这是允许的 C#语言规范,版本4。
In C#, this is allowed, as per the C# Language Specication, version 4.
节 1.10枚举
没有提到可能性,但稍后在 14枚举
,我们看到(在 14.3
):
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
}
显示一个枚举,其中两个枚举成员 - Blue
和 Max
- 具有相同的关联值。
shows an enum in which two enum members - Blue
and Max
- have the same associated value.
这篇关于同一个整数可以有多个枚举值吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文