Type.IsInterface プロパティ

定義

Type がインターフェイスである (つまり値型やクラスではない) ことを示す値を取得します。

public:
 property bool IsInterface { bool get(); };
public bool IsInterface { get; }
member this.IsInterface : bool
Public ReadOnly Property IsInterface As Boolean

プロパティ値

Boolean

true がインターフェイスである場合は Type。それ以外の場合は false

実装

次の例では、インターフェイスを作成し、インターフェイス型を確認し、クラスにプロパティが設定されているかどうかを示し IsInterface ます。

using namespace System;

// Declare an interface.
interface class myIFace{};
public ref class MyIsInterface{};

void main()
{
   try
   {
      // Get the IsInterface attribute for myIFace.
      bool myBool1 = myIFace::typeid->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 = MyIsInterface::typeid->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 );
   }
}
/* The example produces the following output:

Is the specified type an interface? True.
Is the specified type an interface? False.
*/
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);
        }
    }
}
/* The example produces the following output:

Is the specified type an interface? True.
Is the specified type an interface? False.
*/
' Declare an interface.
Interface myIFace
End Interface

Class MyIsInterface
    Public Shared Sub Main()
        ' Get the IsInterface attribute for myIFace.
        Dim myBool1 As Boolean = GetType(myIFace).IsInterface
        Console.WriteLine("Is the specified type an interface? {0}.", myBool1)

        ' Determine whether Example is an interface.
        Dim myBool2 As Boolean = GetType(MyIsInterface).IsInterface
        Console.WriteLine("Is the specified type an interface? {0}.", myBool2)
        Console.ReadLine()

    End Sub
End Class
' The example displays the following output:
'       Is the specified type an interface? True.
'       Is the specified type an interface? False.

注釈

は、 ClassSemanticsMask 型宣言をクラス、インターフェイス、または値型として識別します。

現在のが Type ジェネリック型またはジェネリックメソッドの定義の型パラメーターを表している場合、このプロパティは常にを返し false ます。

このプロパティは読み取り専用です。

適用対象

こちらもご覧ください