그림자와 과부하에 대해 VB.net이 매우 이상하다는 것을 알았지 만,이 사실을 완전히 당황스럽게 생각합니다.그림자가 함수에서 사용될 때 이상하게 동작 함
다음과 비슷한 모델로 작업하고 있습니다. 상위 클래스 :
Public Class Base
Function F() As String
Return "F() in Base Class"
End Function
Function F(ByVal n As Integer) As String
Return "F(" + n.ToString() + ") in Base Class"
End Function
End Class
이 :
Class Derived
Inherits Base
Shadows Function F() As String
Return "-"
End Function
End Class
은 다음 실행시 :
Sub Main()
Dim parent As Base = New Base()
Dim child As Derived = New Derived()
Console.WriteLine(parent.F())
Console.WriteLine(parent.F(1))
Console.WriteLine("------------")
Console.WriteLine(child.F())
Console.WriteLine(child.F(1)) 'this should not compile, due to the shadow keyword.
Console.Read()
End Sub
IndexOutOfRangeException가 발생합니다. 또한, 파생 클래스에서 변경하는 경우 : 의 경우 "-" 을 반환합니다. "파생 클래스의 Func"을 반환합니다. 콘솔은 문자 'u'를 인쇄합니다. 누군가이 이유를 알고 있습니까?