Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

Type.IsInterface Property

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

[Visual Basic]
Public ReadOnly Property IsInterface As Boolean
[C#]
public bool IsInterface {get;}
[C++]
public: __property bool get_IsInterface();
[JScript]
public function get IsInterface() : Boolean;

Property Value

true if the Type is an interface; otherwise, false.

Remarks

The ClassSemanticsMask distinguishes a type declaration as class, interface or value type.

This property is read-only.

Example

[Visual Basic, C#, C++] The following example creates an interface, checks for the interface type, and indicates whether a class has the IsInterface property set.

[Visual Basic] 
Imports System
Imports Microsoft.VisualBasic
' Declare an interface.
Interface myIFace
End Interface 'myIFace
Class MyIsInterface
    Public Shared Sub Main()
        Try
            ' Get the IsInterface attribute for myIFace.
            Dim myBool1 As Boolean = GetType(myIFace).IsInterface
            ' Display the IsInterface attribute for myIFace.
            Console.WriteLine("Is the specified type an interface? {0}.", myBool1.ToString)
            ' Get the IsInterface attribute for MyIsInterface.
            Dim myBool2 As Boolean = GetType(MyIsInterface).IsInterface
            ' Display the IsInterface attribute for MyIsInterface.
            Console.WriteLine("Is the specified type an interface? {0}.", myBool2.ToString)
        Catch e As Exception
            Console.WriteLine(ControlChars.Cr + "An exception occurred: {0}", e.Message.ToString)
        End Try
    End Sub 'Main
End Class 'MyIsInterface

[C#] 
using System;
// Declare an interface.
interface myIFace
{
}
class MyIsInterface 
{
    public static void Main(string []args)
    {
        try
        {
            // Get the IsInterface attribute for myIFace.
            bool myBool1 = typeof(myIFace).IsInterface;    
            //Display the IsInterface attribute for myIFace.
            Console.WriteLine("Is the specified type an interface? {0}.", myBool1);
            // Get the attribute IsInterface for MyIsInterface.
            bool myBool2 = typeof(MyIsInterface).IsInterface;    
            //Display the IsInterface attribute for MyIsInterface.
            Console.WriteLine("Is the specified type an interface? {0}.", myBool2);         
        }
        catch(Exception e)
        {
            Console.WriteLine("\nAn exception occurred: {0}.", e.Message);
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
// Declare an interface.
public __gc __interface myIFace {
};

public __gc class MyIsInterface {
};

void main() {
   try {
      // Get the IsInterface attribute for myIFace.
      bool myBool1 = __typeof(myIFace)->IsInterface;
      //Display the IsInterface attribute for myIFace.
      Console::WriteLine(S"Is the specified type an interface? {0}.", __box( myBool1));
      // Get the attribute IsInterface for MyIsInterface.
      bool myBool2 = __typeof(MyIsInterface)->IsInterface;
      //Display the IsInterface attribute for MyIsInterface.
      Console::WriteLine(S"Is the specified type an interface? {0}.", __box( myBool2));
   } catch (Exception* e) {
      Console::WriteLine(S"\nAn exception occurred: {0}.", e->Message);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Type Class | Type Members | System Namespace | TypeAttributes | IsClass | IsValueType

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft