Type.IsInterface Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene un valore che indica se è un'interfaccia Type , ovvero non una classe o un tipo valore.
public:
property bool IsInterface { bool get(); };
public bool IsInterface { get; }
member this.IsInterface : bool
Public ReadOnly Property IsInterface As Boolean
Valore della proprietà
true se è un'interfaccia Type ; in caso contrario, false.
Implementazioni
Esempio
Nell'esempio seguente viene creata un'interfaccia, viene verificata la presenza del tipo di interfaccia e viene indicato se una classe ha impostato la IsInterface proprietà .
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.
type myIFace = interface end
type MyIsInterface = class end
try
// Get the IsInterface attribute for myIFace.
let myBool1 = typeof<myIFace>.IsInterface
//Display the IsInterface attribute for myIFace.
printfn $"Is the specified type an interface? {myBool1}."
// Get the attribute IsInterface for MyIsInterface.
let myBool2 = typeof<MyIsInterface>.IsInterface
//Display the IsInterface attribute for MyIsInterface.
printfn $"Is the specified type an interface? {myBool2}."
with e ->
printfn $"\nAn exception occurred: {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.
Commenti
Distingue ClassSemanticsMask una dichiarazione di tipo come classe, interfaccia o tipo valore.
Se l'oggetto corrente Type rappresenta un parametro di tipo nella definizione di un tipo generico o di un metodo generico, questa proprietà restituisce falsesempre .
Questa proprietà è di sola lettura.