Type.IsInterface Type.IsInterface Type.IsInterface Type.IsInterface Property

定義

取得值,指出 Type 是否為介面;也就是說,不是類別或實值類型。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

屬性值

如果 true 是介面,則為 Type,否則為 falsetrue if the Type is an interface; otherwise, false.

實作

範例

下列範例會建立介面、檢查介面類別型,並指出類別是否已IsInterface設定屬性。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 );
   }
}
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);
        }
    }
}
' Declare an interface.
Interface IInterface
End Interface

Class Example : Implements IInterface
   Public Shared Sub Main()
      ' Determine whether IInterface is an interface.
       Dim isInterface1 As Boolean = GetType(IInterface).IsInterface
       Console.WriteLine("Is IInterface an interface? {0}", isInterface1)

       ' Determine whether Example is an interface.
       Dim isInterface2 As Boolean = GetType(Example).IsInterface
       Console.WriteLine("Is Example an interface? {0}", isInterface2)
   End Sub 
End Class 
' The example displays the following output:
'       Is IInterface an interface? True
'       Is Example an interface? False

備註

ClassSemanticsMask將類型宣告區分為類別、介面或實數值型別。The ClassSemanticsMask distinguishes a type declaration as class, interface or value type.

如果目前Type的表示泛型型別或泛型方法定義中的類型參數,則這個屬性false一律會傳回。If the current Type represents a type parameter in the definition of a generic type or generic method, this property always returns false.

這個屬性是唯讀的。This property is read-only.

適用於

另請參閱