Export (0) Print
Expand All

Type.IsAbstract Property

Gets a value indicating whether the Type is abstract and must be overridden.

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

Property Value

true if the Type is abstract; otherwise, false.

Example

[Visual Basic, C#, C++] The following example returns true if the specified object is abstract (MustOverride in Visual Basic); otherwise, it returns false.

[Visual Basic] 
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic
Public MustInherit Class MyMustInheritClass
End Class 'MyMustInheritClass
Public Class [MyClass]
End Class '[MyClass]
Public Class Type_IsMustInherit
    Public Shared Sub Main()
        Try
            ' Check whether the return type of MyMustInheritClass is MustInherit or not.
            Console.WriteLine(ControlChars.NewLine + "Checking whether the type is MustInherit." + ControlChars.NewLine)

            If GetType([MyMustInheritClass]).IsAbstract = True Then
                Console.WriteLine("MyMustInheritClass is {0}", "a MustInherit class.")
            Else
                Console.WriteLine("MyMustInheritClass is {0}", "not a MustInherit class.")
            End If
            ' Check whether the return type of MyClass is MustInherit or not.
            If GetType([MyClass]).IsAbstract = True Then
                Console.WriteLine("MyClass is {0}", "a MustInherit class.")
            Else
                Console.WriteLine("MyClass is {0}", "not a MustInherit class.")
            End If
        Catch e As Exception
            Console.WriteLine("Exception: {0} " + ControlChars.Cr, e.Message.ToString())
        End Try
    End Sub 'Main
End Class 'Type_IsMustInherit

[C#] 

using System;
using System.Reflection;
public abstract class MyAbstractClass 
{
}
public class MyClass
{
}
public class Type_IsAbstract
{
    public static void Main()
    {
        try
        {
            // Check whether the return type of MyAbstractClass is abstract or not.
            Console.WriteLine("\nChecking whether the type is abstract.\n"); 
            Console.WriteLine("MyAbstractClass is {0}", (typeof(MyAbstractClass).IsAbstract) ? "an abstract class." : "not an abstract class.");
            // Check whether the return type of MyClass is abstract or not.
            Console.WriteLine("MyClass is {0}", (typeof(MyClass).IsAbstract) ? "an abstract class." : "not an abstract class.");
        }
        catch( Exception e )
        {
            Console.WriteLine( "Exception: {0} \n", e.Message ); 
        }
    }
}

[C++] 

#using <mscorlib.dll>

using namespace System;
using namespace System::Reflection;
public __gc class MyAbstractClass {
   virtual f() = 0; // pure virtual function makes this class abstract.
};
public __gc class MyClass {
};
int main() {
   try {
      // Check whether the return type of MyAbstractClass is abstract or not.
      Console::WriteLine(S"\nChecking whether the type is abstract.\n");
      Console::WriteLine(S"MyAbstractClass is {0}", (__typeof(MyAbstractClass)->IsAbstract) ? S"an abstract class." : S"not an abstract class.");
      // Check whether the return type of MyClass is abstract or not.
      Console::WriteLine(S"MyClass is {0}", (__typeof(MyClass)->IsAbstract) ? S"an abstract class." : S"not an abstract class.");
   } catch (Exception* e) {
      Console::WriteLine(S"Exception: {0} \n", 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

Show:
© 2014 Microsoft