Assign int value to the custom enum property

This question already has an answer here:

  • Cast int to enum in C# 21 answers

  • Just cast the int to the enum .

    o.MyEnum = (CustomEnumProp) myInt;
    

    You can also use the Enum.IsDefined method to check that the int is valid.

    if (Enum.IsDefined(typeof(CustomEnumProp), myInt))
       o.MyEnum = (CustomEnumProp) myInt;
    
    链接地址: http://www.djcxy.com/p/22522.html

    上一篇: 我如何从枚举类型的名称和int获取枚举名称

    下一篇: 将int值分配给自定义枚举属性