How can I cast int to enum?

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

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

30条回答
  •  旧巷少年郎
    2020-11-22 01:21

    From a string: (Enum.Parse is out of Date, use Enum.TryParse)

    enum Importance
    {}
    
    Importance importance;
    
    if (Enum.TryParse(value, out importance))
    {
    }
    

提交回复
热议问题