0 Comments

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"
           }
       }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Related Posts