Answers for "get enum from int"

C#
2

get enum int by name

int enumInt = (int) Enum.Parse(typeof(Your_Enum), string_name);
Posted by: Guest on February-12-2021
1

C# .net core convert int to enum

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

  OR:

if (Enum.IsDefined(typeof(YourEnum), yourInt))
{
    return (YourEnum) Enum.ToObject(typeof(YourEnum), yourInt);
}
Posted by: Guest on April-27-2020

C# Answers by Framework

Browse Popular Code Answers by Language