C# – Get int value from enum
The simplest way to get an enum’s int value is by casting it to an int. Here’s an example: This outputs the following: When the enum is generic (of type ‘Enum’) You can’t cast a generic ‘Enum’ to int, otherwise you get a compiler error (CS0030 Cannot convert type ‘System.Enum’ to ‘int’). Use Convert.Int32() instead. … Read more