Leer en inglés

Compartir a través de


Type.IsInterface Propiedad

Definición

Obtiene un valor que indica si Type es una interfaz, es decir, no es una clase ni un tipo de valor.

C#
public bool IsInterface { get; }

Valor de propiedad

Boolean

Es true si Type es una interfaz; en caso contrario, es false.

Implementaciones

Ejemplos

En el ejemplo siguiente se crea una interfaz, se comprueba el tipo de interfaz y se indica si una clase tiene IsInterface establecida la propiedad .

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

Comentarios

distingue ClassSemanticsMask una declaración de tipo como clase, interfaz o tipo de valor.

Si el objeto actual representa un parámetro de tipo en la definición de un tipo genérico o un método Type genérico, esta propiedad siempre devuelve false .

Esta propiedad es de sólo lectura.

Se aplica a

Producto Versiones
.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

Consulte también