enum Latters { A=1, B = 2, C = 3, D = 4,E=5,F=6,G=7 };
string[] stringLatters = { "0", "2", "8", "H", "C", "D", "E, I" };
foreach (string stringLatter in stringLatters)
{
try {
Latters Latter = (Latters) Enum.Parse(typeof(Latters), stringLatter);
if (Enum.IsDefined(typeof(Latters), Latter) | Latter.ToString().Contains(","))
Console.WriteLine("Converted '{0}' to {1}.", stringLatter, Latter.ToString());
else
Console.WriteLine("{0} is not an underlying value of the Latters enumeration.", stringLatter);
}
catch (ArgumentException) {
Console.WriteLine("'{0}' is not a member of the Latters enumeration.", stringLatter);
}
}
// The example displays the following output:
// Converted '1' to A.
// Converted '2' to B.
// 8 is not an underlying value of the Latters enumeration.
// 'H' is not a member of the Latters enumeration.
// Converted 'C' to C.
// 'I' is not a member of the Latters enumeration.
// Converted 'D, D' to E, E.//Converting enum to string
string USERTYPE = UserType.CL.ToString() ;