Freigeben über


Type.IsAbstract Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public ReadOnly Property IsAbstract As Boolean
public bool IsAbstract { get; }

Property Value

Type: System.Boolean
true if the Type is abstract; otherwise, false.

Remarks

If the current Type represents a type parameter in the definition of a generic type or generic method, this property always returns false.

Examples

The following example returns true if the specified object is abstract; otherwise, it returns false.

Imports System.Reflection
Public MustInherit Class MyMustInheritClass
End Class 'MyMustInheritClass
Public Class [MyClass]
End Class '[MyClass]
Public Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Try
         ' Check whether the return type of MyMustInheritClass is MustInherit or not.
         outputBlock.Text &= ControlChars.NewLine + "Checking whether the type is MustInherit." + ControlChars.NewLine & vbCrLf

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

using System;
using System.Reflection;
public abstract class MyAbstractClass
{
}
public class MyClass
{
}
public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      try
      {
         // Check whether the return type of MyAbstractClass is abstract or not.
         outputBlock.Text += "\nChecking whether the type is abstract.\n" + "\n";
         outputBlock.Text += String.Format("MyAbstractClass is {0}", (typeof(MyAbstractClass).IsAbstract) ? "an abstract class." : "not an abstract class.") + "\n";
         // Check whether the return type of MyClass is abstract or not.
         outputBlock.Text += String.Format("MyClass is {0}", (typeof(MyClass).IsAbstract) ? "an abstract class." : "not an abstract class.") + "\n";
      }
      catch (Exception e)
      {
         outputBlock.Text += String.Format("Exception: {0} \n", e.Message) + "\n";
      }
   }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.