IsFinal Property

MethodBase.IsFinal Property

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Gets a value that indicates whether this method is final (NotOverridable in Visual Basic).

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

Public ReadOnly Property IsFinal As Boolean

Property Value

Type: System.Boolean
true if this method is final; otherwise, false.

To determine whether 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 that is non-virtual might implement an interface method. The common language runtime requires all methods that implement interface members to be marked as virtual; therefore, the compiler marks the method virtual final. Thus there are cases where a method that is marked as virtual is not overridable.

To establish with certainty whether a method is overridable, use C# code such as if (MethodInfo.IsVirtual && !MethodInfo.IsFinal) or Visual Basic code such as MethodInfo.IsVirtual And Not MethodInfo.IsFinal.

The following example displays false for IsFinal, which might lead you to think that MyMethod is overridable. MyMethod is not marked virtual and therefore cannot be overridden.

Imports System.Reflection

Public Class Example

   Public Sub MyMethod()
   End Sub

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      Dim m As MethodBase = GetType(Example).GetMethod("MyMethod")
      outputBlock.Text += String.Format("The IsFinal property value of MyMethod is {0}.", m.IsFinal) & vbCrLf
      outputBlock.Text += String.Format("The IsVirtual property value of MyMethod is {0}.", m.IsVirtual) & vbCrLf
   End Sub
End Class

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

© 2017 Microsoft