Type.IsInterface Свойство
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
В этой статье
Возвращает значение, позволяющее определить, является ли объект Type интерфейсом (иными словами, не является классом или типом значения).
public:
property bool IsInterface { bool get(); };
public bool IsInterface { get; }
member this.IsInterface : bool
Public ReadOnly Property IsInterface As Boolean
Значение true
, если объект Type является интерфейсом; в противном случае — значение false
.
В следующем примере создается интерфейс, проверяется тип интерфейса и указывается, имеет ли класс IsInterface
свойство.
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.
ClassSemanticsMaskКомпонент различает объявление типа как класс, интерфейс или тип значения.
Если Current Type представляет параметр типа в определении универсального типа или универсального метода, это свойство всегда возвращает значение false
.
Это свойство доступно только для чтения.
Продукт | Версии |
---|---|
.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 |