Type.IsInterface Proprietà

Definizione

Ottiene un valore che indica se Type è un'interfaccia, ovvero non è una classe né un tipo di valore.

C#
public bool IsInterface { get; }

Valore della proprietà

Boolean

true se Type è un'interfaccia; in caso contrario, false.

Implementazioni

Esempio

Nell'esempio seguente viene creata un'interfaccia , viene verificato il tipo di interfaccia e viene indicato se per una classe è impostata IsInterface la proprietà .

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

Commenti

Distingue ClassSemanticsMask una dichiarazione di tipo come classe, interfaccia o tipo valore.

Se l'oggetto corrente rappresenta un parametro di tipo nella definizione di un tipo generico o di un metodo Type generico, questa proprietà restituisce sempre false .

Questa proprietà è di sola lettura.

Si applica a

Prodotto Versioni
.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

Vedi anche