@Steve - Here is the Class and Conversion code. You also also assign different integer values to enum (not in sequence) and it will work like charm.
public enum Products
{
[Description("Product A")]
ProductA = 1,
[Description("Product B")]
ProductB = 2,
[Description("Product C")]
ProductC = 3
}
Conversion
string numericOutput = $" {(int)Products.ProductA}, {(int)Products.ProductB}, {(int)Products.ProductC}";
Console.WriteLine(numericOutput); // 1, 2, 3
string enumOutput = $" {(Products)1}, {(Products)2}, {(Products)3}";
Console.WriteLine(enumOutput);//ProductA, ProductB, ProductC
Dynamically handling of inputs
for (int i = 0; i < 5; i++)
{
Products products;
if (Enum.TryParse(i.ToString(), true, out products) && Enum.IsDefined(typeof(Products), products))
Console.WriteLine("Converted '{0}' to {1}", i.ToString(), products.ToString());
else
Console.WriteLine("{0} is not a value of the enum", i.ToString());
}
//output
0 is not a value of the enum
Converted '1' to ProductA
Converted '2' to ProductB
Converted '3' to ProductC
4 is not a value of the enum