using System;
namespace ConsoleApplication_C_Sharp
{
static class Program
{
enum Colors { Black = 0, Red = 1, Green = 2, Blue = 3 };
static void Main(string[] args)
{
string[] arr = { "0", "1", "3", "5", "Red", "Green", "Blue", "Grey"};
foreach (string s in arr)
{
Colors color;
if (Enum.TryParse(s, out color))
if (Enum.IsDefined(typeof(Colors), color))
Console.WriteLine("{0} = {1}", s, color.ToString());
else
Console.WriteLine("{0} - is not in enum", s);
else
Console.WriteLine("{0} - is not in enum", s);
}
}
}
}
/*
run:
0 = Black
1 = Red
3 = Blue
5 - is not in enum
Red = Red
Green = Green
Blue = Blue
Grey - is not in enum
*/