本文介绍了枚举,重叠值,C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
提前道歉,因为我敢肯定有人一定曾经问过这个,但我找不到。
Apologies in advance as I'm sure someone must have asked this before but I can't find it.
一个同事和我都感到惊讶将相同的值添加到一个枚举中,然后对其进行编译,例如
Just had a surprise, a colleague and I both added the same value in for an enum, and it compiled, e.g.
enum MyEnum
{
mine = 1,
his = 1
}
看起来像C / C ++支持这也是 (?)。出于任何原因,是否有用?我看到了一种人类语言不同的案例(一个= 1,eins = 1,等等),但我不相信
Looks like C/C++ supports this also (?). Any reason for this behaviour, any cases where it's useful? I saw one case with difference human languages (one = 1, eins = 1, etc) but I'm not convinced
谢谢
推荐答案
让我们举一个简单的例子
Let's take a simple example
enum PrivilegeLevel
{
None,
Reporter,
Reviewer,
Admin,
DefaultForNewUser = None,
DefaultForProjectOwner = Reviewer,
};
这篇关于枚举,重叠值,C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!