gpt4 book ai didi

.net - 基类中的地址

转载 作者:行者123 更新时间:2023-12-04 00:47:48 25 4
gpt4 key购买 nike

当引用一个方法的地址时,我们是否应该考虑重写?

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

最佳答案

它将打印 B。为了更清楚地表明您的意图,您可以放置​​ AddressOf Me.Foo。另外,仅供引用,如果您放置 MyClass.Foo,它将打印 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

关于.net - 基类中的地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5327138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com