When referencing a method's address, should we take into account the overriding or not?
Class B
Inherits A
Overrides Sub Foo
Console.WriteLine("B")
End Sub
End Class
Class A
Public Sub PFoo
... AddressOf Foo ... ' WHAT WILL DO THIS METHOD??? '
End
Protected Overridable Sub Foo()
Console.WriteLine("A")
End Sub
End Class
It will print B. To make it more obvious on what your intent is, you could put AddressOf Me.Foo. Also, just as an FYI, if you put MyClass.Foo, it will print A
Module Module1
Sub Main()
Dim b As B = New B
b.PFoo() ' prints B
Console.ReadLine()
End Sub
End Module
Public Class B
Inherits A
Protected Overrides Sub Foo()
Console.WriteLine("B")
End Sub
End Class
Public Class A
Public Sub PFoo()
Dim f As Action = New Action(AddressOf Me.Foo)
f.Invoke()
End Sub
Protected Overridable Sub Foo()
Console.WriteLine("A")
End Sub
End Class
I believe that PFoo will reference Foo that is overridden in the inheriting class, if PFoo is called within the inheriting B class's/object instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With