Parsing the enumerator value to integer will give us the desired result. See below the sample code to get integer value from enumerator in C#.
- class Program
- {
- static void Main(string[] args)
- {
- int intVal = (int)LevelEnum.Three;
- Console.WriteLine(intVal);
- }
- }
The result will be 3.
- public enum LevelEnum
- {
- One = 1,
- Two = 2,
- Three = 3,
- Four = 4
- }
No comments:
Post a Comment