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.
我正在寻找一种将 int 转换为枚举的方法,例如
var result = (MyEnum)value;
问题是我只有整数和 System.Type。
这不起作用:
var result = (type)value;
谢谢你的帮助。
您可以使用:
Enum.ToObject(type, value);
尽管如果您在编译时不知道类型是什么,我不知道您希望如何使用该结果。