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.Gets a value indicating whether the Type is an interface; that is, not a class or a value type.

public:
 property bool IsInterface { bool get(); };
public bool IsInterface { get; }
member this.IsInterface : bool
Public ReadOnly Property IsInterface As Boolean

Valor de propiedad

Boolean

Es true si Type es una interfaz; en caso contrario, es false.true if the Type is an interface; otherwise, 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.The following example creates an interface, checks for the interface type, and indicates whether a class has the IsInterface property set.

using namespace System;

// Declare an interface.
interface class myIFace{};
public ref class MyIsInterface{};

void main()
{
   try
   {
      // Get the IsInterface attribute for myIFace.
      bool myBool1 = myIFace::typeid->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 = MyIsInterface::typeid->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.
*/
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.
*/
' Declare an interface.
Interface myIFace
End Interface

Class MyIsInterface
    Public Shared Sub Main()
        ' Get the IsInterface attribute for myIFace.
        Dim myBool1 As Boolean = GetType(myIFace).IsInterface
        Console.WriteLine("Is the specified type an interface? {0}.", myBool1)

        ' Determine whether Example is an interface.
        Dim myBool2 As Boolean = GetType(MyIsInterface).IsInterface
        Console.WriteLine("Is the specified type an interface? {0}.", myBool2)
        Console.ReadLine()

    End Sub
End Class
' The example displays the following output:
'       Is the specified type an interface? True.
'       Is the specified type an interface? False.

Comentarios

ClassSemanticsMaskDistingue una declaración de tipos como clase, interfaz o tipo de valor.The ClassSemanticsMask distinguishes a type declaration as class, interface or value type.

Si el actual Type representa un parámetro de tipo en la definición de un tipo genérico o de un método genérico, esta propiedad siempre devuelve false .If the current Type represents a type parameter in the definition of a generic type or generic method, this property always returns false.

Esta propiedad es de sólo lectura.This property is read-only.

Se aplica a

Consulte también