Ler em inglês

Compartilhar via


Type.IsInterface Propriedade

Definição

Obtém um valor que indica se o Type é uma interface, ou seja, não é uma classe ou um tipo de valor.

C#
public bool IsInterface { get; }

Valor da propriedade

Boolean

true se o Type é uma interface; caso contrário, false.

Implementações

Exemplos

O exemplo a seguir cria uma interface, verifica o tipo de interface e indica se uma classe tem a IsInterface propriedade definida.

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

Comentários

O ClassSemanticsMask distingue uma declaração de tipo como classe, interface ou tipo de valor.

Caso o Type atual represente um parâmetro de tipo na definição de um tipo genérico ou um método genérico, esta propriedade sempre retorna false.

Esta propriedade é somente para leitura.

Aplica-se a

Produto Versões
.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

Confira também