The IsDefined method returns true if a given integral value, or its name as a string, is present in a specified enum.
The following is our enum −
enum Subjects { Maths, Science, English, Economics };
The above is initialized by default i.e.
Maths = 0, Science = 1, English = 2, Economics = 3
Therefore, when we will find 3 using IsDefined(), then it will return True as shown below −
using System; public class Demo { enum Subjects { Maths, Science, English, Economics }; public static void Main() { object ob; ob = 3; Console.WriteLine("{0} = {1}", ob, Enum.IsDefined(typeof(Subjects), ob)); } }
3 = True