Type.IsInterface Właściwość

Definicja

Pobiera wartość wskazującą, czy jest interfejsem, czyli nie klasą Type czy typem wartości.

C#
public bool IsInterface { get; }

Wartość właściwości

Boolean

true, jeśli Type element jest interfejsem; w przeciwnym razie . false

Implementuje

Przykłady

Poniższy przykład tworzy interfejs, sprawdza typ interfejsu i wskazuje, czy klasa ma IsInterface zestaw właściwości.

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.
*/

Uwagi

Klasa ClassSemanticsMask rozróżnia deklarację typu jako klasę, interfejs lub typ wartości.

Jeśli bieżąca wartość reprezentuje parametr typu w definicji typu ogólnego lub metody ogólnej, ta właściwość Type zawsze zwraca wartość false .

Ta właściwość jest tylko do odczytu.

Dotyczy

Produkt Wersje
.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

Zobacz też