25 May, 2009
0 Comments
0 categories
If you want to check if a string is defined in an enum, with C#, use the Enum.IsDefined function
public enum CarTypes { Alfa, Audi, BMW } public void TestEnum() { if (Enum.IsDefined(typeof(CarTypes), "Audi")) { Console.WriteLine("Yes the string Audi is an entry in the enum CarTypes" } }
Tags: C#