Below you will find pages that utilize the taxonomy term “Csharp”
Posts
read more
C# enum
How one can get variants’ names and their integer values from enum in C#? Consider the following example:
var variant = TestEnum.Bar;
Console.WriteLine($"{variant}: {(int)variant}");
enum TestEnum
{
Foo,
Bar,
Baz
}
Running this code will produce
Bar: 1
So enum’s ToString()
methods returns the name of the variant, and an enum
member can be cast to integer to get its value.