Converting an Enum to Integer in C#

If you need to convert an enum to its numeric equivalent , you can simply cast the values to integer .

Below is a sample code snippet that demonstrates how to do it.

Converting an Enum to Integer in C#

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace AbundantcodeConsoleApp
{
    enum EmployeeDesignation
    {
        Trainee=1,
        SoftwareEngineer = 2,
        SeniorSoftwareEngineer=5
    };
    internal class Program
    {
        private static void Main(string[] args)
        {
            int design = (int)EmployeeDesignation.SoftwareEngineer;
            Console.WriteLine(design);
            Console.ReadLine();
        }     
    }
    
}
1
%d