Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个具有如下描述属性的枚举:
public enum MyEnum { Name1 = 1, [Description("Here is another")] HereIsAnother = 2, [Description("Last one")] LastOne = 3 }
我的“最后一个”值为 3
返回的代码是什么?
你可以这样做
int lastOneValue = (int) MyEnum.LastOne;
此代码返回值 2 而不是“LastOne”
string lastOneString = MyEnum.LastOne.ToString();
此代码将“LastOne”作为字符串值返回
MyEnum mynum = MyEnum.LastOne;
此代码创建新对象MyEnum并将其值设置为“LastOne”
MyEnum