草庐IT

c# - 在 C# 中的运行时设置枚举值

有什么方法可以在运行时更改enum值?例如我有以下类型enumMyType{TypeOne,//=5atruntimeTypeTwo//=3atruntime}我想在运行时将5设置为TypeOne,将3设置为TypeTwo。 最佳答案 正如其他人所指出的,答案是否定的。但是您可以重构您的代码以改用类:publicsealedclassMyType{publicintTypeOne{get;set;}publicintTypeTwo{get;set;}}...varmyType=newMyType{TypeOne=5,TypeTwo=