Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# Enum IsDefined Method
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 −
Example
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));
}
}
Output
3 = True
Advertisements
