The implementation of vb.net is different from the implementation of C # in many aspects. Today we will compare it with Overload.
Everyone may be familiar with C #. Let me list a piece of code:
Namespace OverloaddingCS
{
Public class Test
{
Public static void Main ()
{
Derived d = new Derived ();
D. WriteLine (10 );
D. WriteLine ("11 ");
DS. WriteLine (10.5 );
}
}
Class Base
{
Public void WriteLine (String AnyString)
{
Console. WriteLine (AnyString + "called Base: String ");
}
Public void WriteLine (int AnyInteger)
{
Console. WriteLine (AnyInteger. ToString () + "called Base: Integer ");
}
}
Class Derived: Base
{
Public void WriteLine (double AnyDouble)
{
Console. WriteLine (AnyDouble. ToString () + "called Derived: double ");
}
}
}
The answer is simple. If you are familiar with c ++
10 called Derived: double
11 called Base: String
10.5 called Derived: double
If I translate similar code into vb.net, note that it is the original translation.
Class TestClass Test
Public Shared Sub Main ()
Dim objMyTest As New Derived
With objMyTest
. WriteLine (10)
. WriteLine ("11 ")
. WriteLine (10.5)
End
Console. ReadLine ()
End Sub
End Class
Class BaseClass Base
Public Sub WriteLine () Sub WriteLine (ByVal AnyString As String)
Console. WriteLine (AnyString + "called Base: String ")
End Sub
Public Sub WriteLine () Sub WriteLine (ByVal AnyInteger As Integer)
Console. WriteLine (AnyInteger. ToString + "called Base: Integer ")
End Sub
End Class
Class DerivedClass Derived: Inherits Base
Public Overloads Sub WriteLine () Sub WriteLine (ByVal AnyDouble As Double)
Console. WriteLine (AnyDouble. ToString + "called Derived: Double ")
End Sub
End Class
The beginning of the Code is the same. I directly published the results, starting with a different result from C #.
10 called Base: Integer
11 called Base: String
10.5 called Derived: Double
The results are unexpected, And the beginning is also reasonable.
I will not explain it. The key is to remind you that when you have C ++ special VB. NET, do not take it for granted that the processing method of VB. NET is the same as that of C.