英語で読む

次の方法で共有


Type.IsInterface プロパティ

定義

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

C#
public bool IsInterface { get; }

プロパティ値

Boolean

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

実装

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

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);
        }
    }
}
/* The example produces the following output:

Is the specified type an interface? True.
Is the specified type an interface? False.
*/

注釈

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

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

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

適用対象

製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
.NET Standard 2.0, 2.1

こちらもご覧ください