Export (0) Print
Expand All

Type.IsClass Property

Gets a value indicating whether the Type is a class; that is, not a value type or interface.

[Visual Basic]
Public ReadOnly Property IsClass As Boolean
[C#]
public bool IsClass {get;}
[C++]
public: __property bool get_IsClass();
[JScript]
public function get IsClass() : Boolean;

Property Value

true if the Type is a class; otherwise, false.

Remarks

This property returns true for Type instances representing Enum and ValueType.

The ClassSemanticsMask distinguishes a type declaration as class, interface, or value type.

This property is read-only.

Example

[Visual Basic, C#, C++] The following example creates an instance of a type and indicates whether the type is a class.

[Visual Basic] 
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public Class MyDemoClass
End Class 'MyDemoClass
Public Class MyTypeClass
    Public Shared Sub Main()
        Try
            Dim myType As Type = 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 'Main
End Class 'MyTypeClass

[C#] 
using System;
using System.Reflection;
public  class MyDemoClass
{
}
public class MyTypeClass
{
    public static void Main(string[] args)
    {
        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);
        }
    }
}

[C++] 
#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;

public __gc class MyDemoClass {
};

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

Type Class | Type Members | System Namespace | TypeAttributes | IsInterface | IsValueType

Show:
© 2014 Microsoft