Type.IsAbstract Property

Definition

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

C#
public bool IsAbstract { get; }

Property Value

true if the Type is abstract; otherwise, false.

Implements

Examples

The following example creates an array of Type objects that represent the following types:contains type returns true if the specified object is abstract; otherwise, it returns false.

  • AbstractClass, an abstract class (a class marked as abstract in C# and MustInherit in Visual Basic).

  • DerivedClass, a class that inherits from AbstractClass.

  • SingleClass, a non-inheritable class. it's defined as sealed in C# and NotInheritable in Visual Basic.

  • ITypeInfo, an interface.

  • ImplementingClass, a class that implements the ITypeInfo interface.

The method returns true only for AbstractClass, the abstract class, and ITypeInfo, the interface.

C#
using System;

public abstract class AbstractClass
{}

public class DerivedClass : AbstractClass
{}

public sealed class SingleClass
{}

public interface ITypeInfo
{
   string GetName();
}

public class ImplementingClass : ITypeInfo
{
   public string GetName()
   {
      return this.GetType().FullName;
   }
}

delegate string InputOutput(string inp);

public class Example
{
   public static void Main()
   {
      Type[] types= { typeof(AbstractClass),
                      typeof(DerivedClass),
                      typeof(ITypeInfo),
                      typeof(SingleClass),
                      typeof(ImplementingClass),
                      typeof(InputOutput) };
      foreach (var type in types)
         Console.WriteLine("{0} is abstract: {1}",
                           type.Name, type.IsAbstract);
   }
}
// The example displays the following output:
//       AbstractClass is abstract: True
//       DerivedClass is abstract: False
//       ITypeInfo is abstract: True
//       SingleClass is abstract: False
//       ImplementingClass is abstract: False
//       InputOutput is abstract: False

Remarks

The IsAbstract property returns true in the following cases:

  • The current type is abstract; that is, it cannot be instantiated, but can only serve as the base class for derived classes. In C#, abstract classes are marked with the abstract keyword; in F#, they are marked with the AbstractClass attribute; in Visual Basic, they are marked with the MustInherit keyword.

  • The current type is an interface.

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

Applies to

Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

See also