📜  C# .net core 将 int 转换为 enum - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:52.656000             🧑  作者: Mango

代码示例1
if (Enum.IsDefined(typeof(YourEnum), yourInt))
{
    return (YourEnum) yourInt;
}

  OR:

if (Enum.IsDefined(typeof(YourEnum), yourInt))
{
    return (YourEnum) Enum.ToObject(typeof(YourEnum), yourInt);
}