说我有一个如下的枚举,我希望编号从1000开始。
public enum Fruits : uint
{
Apple = 1000,
Orange = 1001,
Strawberry = 1002,
Banana = 1003,
Blueberry = 1004,
}
为每个Fruit
分配一个数字很繁琐且难以阅读,更不用说如果我有20多个Fruit
,并且可能想对其重新排序或添加/删除Fruit
。是否有类似以下的语法?
public enum Fruits : uint where value >= 1000
{
Apple,
Orange,
Strawberry,
Banana,
Blueberry,
}
答案 0 :(得分:0)
@Fabio在评论中指出,枚举自动值基于先前枚举的值,因此以下代码段的编译方式相同:
public enum Fruits : uint
{
Apple = 1000,
Orange = 1001,
Strawberry = 1002,
Banana = 1003,
Blueberry = 1004,
}
public enum Fruits : uint
{
Apple = 1000,
Orange,
Strawberry,
Banana,
Blueberry,
}
谢谢@Fabio!