Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MethodBase.IsFinal Property

Gets a value indicating whether this method is final.

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

Property Value

true if this method is final; otherwise, false.

Remarks

To determine if a method is overridable, it is not sufficient to check that IsVirtual is true. For a method to be overridable, IsVirtual must be true and IsFinal must be false. For example, a method might be non-virtual, but it implements an interface method. The common language runtime requires that all methods that implement interface members must be marked as virtual (Overridable in Visual Basic); therefore, the compiler marks the method virtual (Overridable in Visual Basic) final. So there are cases where a method is marked as virtual (Overridable in Visual Basic) but is still not overridable.

To establish with certainty whether a method is overridable, use code such as this: if (MethodInfo.IsVirtual && !MethodInfo.IsFinal)

If IsVirtual is false or IsFinal is true, then the method cannot be overridden.

Example

The following example displays false for IsFinal, which might lead you to think that MyMethod is overridable. The code prints false even though MyMethod is not marked virtual (Overridable in Visual Basic) and thus cannot be overridden.

[Visual Basic] 
Imports System
Imports System.Reflection
Imports Microsoft.VisualBasic

Public Class MyClass1
    
    Public Sub MyMethod()
    End Sub
    
    Public Shared Sub Main()
        Dim m As MethodBase = GetType(MyClass1).GetMethod("MyMethod")
        Console.WriteLine("The IsFinal property value of MyMethod is {0}.", m.IsFinal)
        Console.WriteLine("The IsVirtual property value of MyMethod is {0}.", m.IsVirtual)
    End Sub
End Class

[C#] 
using System;
using System.Reflection;
 
public class MyClass 
{
    public void MyMethod() 
    {
    }
    public static void Main() 
    {
        MethodBase m = typeof(MyClass).GetMethod("MyMethod");
        Console.WriteLine("The IsFinal property value of MyMethod is {0}.", m.IsFinal);
        Console.WriteLine("The IsVirtual property value of MyMethod is {0}.", m.IsVirtual);
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Reflection;

public __gc class MyClass 
{
public:
    void MyMethod() 
    {
    }
};

int main() 
{
    MethodBase* m = __typeof(MyClass)->GetMethod(S"MyMethod");
    Console::WriteLine(S"The IsFinal property value of MyMethod is {0}.", __box(m->IsFinal));
    Console::WriteLine(S"The IsVirtual property value of MyMethod is {0}.", __box(m->IsVirtual));
}

[JScript] 
import System;
import System.Reflection;
 
 public class MyClass 
 {
 public function MyMethod() : void
   {
   }
 public static function Main() : void 
   {
    var m : MethodBase  = MyClass.GetMethod("MyMethod");
    Console.WriteLine(m.IsFinal);
   }
 }
 MyClass.Main();

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

See Also

MethodBase Class | MethodBase Members | System.Reflection Namespace | Boolean

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft