How can I cast int to enum?

后端 未结 30 1487
礼貌的吻别
礼貌的吻别 2020-11-22 00:56

How can an int be cast to an enum in C#?

30条回答
  •  一生所求
    2020-11-22 01:20

    Sometimes you have an object to the MyEnum type. Like

    var MyEnumType = typeof(MyEnum);
    

    Then:

    Enum.ToObject(typeof(MyEnum), 3)
    

提交回复
热议问题