Check if a method is virtual in CSharp

Description

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

Example


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

public class MyClass 
{
    public void MyMethod() 
    {
    }
    public static void Main() 
    {
        MethodBase m = typeof(MyClass).GetMethod("MyMethod");
        Console.WriteLine(m.IsFinal);
        Console.WriteLine(m.IsVirtual);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type