次の方法で共有


Type.IsInterface プロパティ

Type がインターフェイスであり、クラスや値型でないかどうかを示す値を取得します。

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

プロパティ値

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

解説

ClassSemanticsMask は、クラス、インターフェイス、値型のいずれとして型が宣言されているかを識別します。

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

使用例

[Visual Basic, C#, C++] インターフェイスを作成し、そのインターフェイスの型をチェックして、クラスの IsInterface プロパティが設定されているかどうかを表示する例を次に示します。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, .NET Compact Framework - Windows CE .NET, Common Language Infrastructure (CLI) Standard

参照

Type クラス | Type メンバ | System 名前空間 | TypeAttributes | IsClass | IsValueType