.NET 中的枚举可以有多少个条目?
最佳答案
我很确定底层类型是整数类型(不一定是 int
)。本页 here指出:
The approved types for an enum are byte, sbyte, short, ushort, int, uint, long, or ulong. The underlying type specifies how much storage is allocated for each enumerator.
和:
Just as with any constant, all references to the individual values of an enum are converted to numeric literals at compile time.
所以我建议唯一的限制是
long/ulong
的范围(数十亿)和编译器中用于枚举的允许符号空间(如果您实际上正在创建真正的大量枚举,您很可能首先会遇到该限制)。如果您为枚举指定较小的类型(例如,
short
),则范围将相应缩小。
关于.NET 枚举大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1563995/