Check if a Type is an interface in CSharp

Description

The following code shows how to check if a Type is an interface.

Example


/*from   www  . jav a  2s . co m*/
using System;

interface myIFace
{
}
class MyIsInterface 
{
    public static void Main(string []args)
    {
        bool myBool1 = typeof(myIFace).IsInterface;    
        Console.WriteLine("Is the specified type an interface? {0}.", myBool1);
        bool myBool2 = typeof(MyIsInterface).IsInterface;    
        Console.WriteLine("Is the specified type an interface? {0}.", myBool2);         
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type