Check if a method is abstract in CSharp

Description

The following code shows how to check if a method is abstract.

Example


using System;/* ww w .j a va  2 s.  c  om*/
using System.Reflection;

class methodbase
{
    public static int Main(string[] args)
    {      
        Type MyType1 = Type.GetType("System.Runtime.Serialization.Formatter");       
        Type MyType2 = Type.GetType("System.Reflection.MethodBase");
        MethodBase Mymethodbase1 = MyType1.GetMethod("WriteInt32", BindingFlags.NonPublic|BindingFlags.Instance);

        MethodBase Mymethodbase2 = MyType2.GetMethod("GetCurrentMethod", BindingFlags.Public|BindingFlags.Static);

        Console.Write("\nMymethodbase = " + Mymethodbase1.ToString());
        Console.Write(Mymethodbase1.IsAbstract);
        return 0;
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type