C# Type IsInterface

Description

Type IsInterface gets a value indicating whether the Type is an interface; that is, not a class or a value type.

Syntax

Type.IsInterface has the following syntax.


public bool IsInterface { get; }

Example

The following example creates an interface, checks for the interface type, and indicates whether a class has the IsInterface property set.


using System;/*from  ww w . j a v a 2  s.c  om*/
// Declare an interface. 
interface myIFace
{
}
class MyIsInterface 
{
    public static void Main(string []args)
    {
        try
        {
            Console.WriteLine(typeof(myIFace).IsInterface);
            Console.WriteLine(typeof(MyIsInterface).IsInterface);         
        }
        catch(Exception e)
        {
            Console.WriteLine("\nAn exception occurred: {0}.", e.Message);
        }
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version