The source code to check a specified type is an interface or not is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
//C# program to check a specified type
//is an interface or not.
using System;
using System.Reflection;
interface Inf
{
void Print();
}
class Program
{
static void Main()
{
Type type = typeof(Inf);
if (type.IsInterface== true)
{
Console.WriteLine("Inf is an interface");
}
else
{
Console.WriteLine("Inf is not an interface");
}
}
}
Output:
Inf is an interface
Press any key to continue . . .
Explanation:
In the above program, we created an interface Inf and a class Program. The Inf interface contains the declaration of the Print() method.
The Program class is a non-abstract class that contains Main() method. The Main() method is the entry point for the program. Here, we check the specified type is an interface or not using the IsInterface property of Type class and printed the appropriate message on the console screen.
Program:
The source code to check a specified type is an interface or not is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.
Output:
Explanation:
In the above program, we created an interface Inf and a class Program. The Inf interface contains the declaration of the Print() method.
The Program class is a non-abstract class that contains Main() method. The Main() method is the entry point for the program. Here, we check the specified type is an interface or not using the IsInterface property of Type class and printed the appropriate message on the console screen.