Type.IsClass Properti

Definisi

Mendapatkan nilai yang menunjukkan apakah Type adalah kelas atau delegasi; yaitu, bukan jenis nilai atau antarmuka.

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

Nilai Properti

trueType jika adalah kelas; jika tidak, false.

Penerapan

Contoh

Contoh berikut membuat instans jenis dan menunjukkan apakah jenisnya adalah kelas.

using namespace System;
using namespace System::Reflection;
public ref class MyDemoClass{};

int main()
{
   try
   {
      Type^ myType = Type::GetType( "MyDemoClass" );
      
      // Get and display the 'IsClass' property of the 'MyDemoClass' instance.
      Console::WriteLine( "\nIs the specified type a class? {0}.", myType->IsClass );
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "\nAn exception occurred: {0}.", e->Message );
   }

}
using System;
using System.Reflection;

public  class MyDemoClass
{
}

public class MyTypeClass
{
    public static void Main(string[] args)
    {
        try
        {
            Type  myType = typeof(MyDemoClass);
            // Get and display the 'IsClass' property of the 'MyDemoClass' instance.
            Console.WriteLine("\nIs the specified type a class? {0}.", myType.IsClass);
        }
        catch(Exception e)
        {
            Console.WriteLine("\nAn exception occurred: {0}." ,e.Message);
        }
    }
}
type MyDemoClass = class end

try
    let myType = typeof<MyDemoClass>
    // Get and display the 'IsClass' property of the 'MyDemoClass' instance.
    printfn $"\nIs the specified type a class? {myType.IsClass}."
with e ->
    printfn $"\nAn exception occurred: {e.Message}."
Imports System.Reflection

Public Class MyDemoClass
End Class

Public Class MyTypeClass
    Public Shared Sub Main()
        Try
            Dim myType As Type = GetType(MyDemoClass)
            ' Get and display the 'IsClass' property of the 'MyDemoClass' instance.
            Console.WriteLine(ControlChars.Cr + "Is the specified type a class? {0}.", myType.IsClass.ToString())
        Catch e As Exception
            Console.WriteLine(ControlChars.Cr + "An exception occurred: {0}.", e.Message.ToString())
        End Try
    End Sub
End Class

Keterangan

Properti ini mengembalikan true untuk kelas serta delegasi. Ini mengembalikan false untuk jenis nilai (untuk struktur dan enumerasi) bahkan jika dikotak.

Jika saat ini Type mewakili parameter jenis dalam definisi jenis generik atau metode generik, properti ini selalu mengembalikan true. Jika saat ini Type mewakili jenis generik yang dibangun, properti ini mengembalikan true jika definisi jenis generik adalah definisi kelas; yaitu, itu tidak menentukan antarmuka atau jenis nilai.

Catatan

Properti ini mengembalikan true untuk Type instans yang mewakili Enum kelas dan ValueType . Kedua kelas ini adalah jenis dasar untuk enumerasi dan jenis nilai, masing-masing, tetapi mereka bukan enumerasi atau jenis nilai itu sendiri. Untuk informasi selengkapnya, lihat properti IsValueType dan IsEnum.

Nilai TypeAttributes.ClassSemanticsMask enumerasi membedakan deklarasi jenis sebagai kelas atau antarmuka. Namun, kelas dan jenis nilai ditandai dengan TypeAttributes.Class atribut . Jika Anda mengambil nilai properti Atribut jenis dan menggunakan TypeAttributes.ClassSemanticsMask nilai untuk menentukan apakah jenis adalah kelas alih-alih jenis nilai, Anda juga harus memanggil IsValueType properti . Contoh untuk TypeAttributes enumerasi berisi informasi tambahan serta anexample.

Properti ini bersifat hanya baca.

Berlaku untuk

Lihat juga