出个小问题,看谁能做出
谁能把这段VB代码准确无误地翻译成对等的C#,程序结构(继承结构)不能改变
Public Interface I1
Sub Test()
End Interface
Public Interface I2
Sub Test()
End Interface
Public Class BaseClass : Implements I1, I2
Public Sub TheTest() Implements I1.Test
MyClass.Greeting()
End Sub
Friend Sub AnotherTest() Implements I2.Test
Me.Greeting()
End Sub
Protected Overridable Sub Greeting()
Static i As Integer
i += 1
Console.WriteLine("Hello, Base. For the " & i & "th time(s)")
End Sub
End Class
Public Class SubClass : Inherits BaseClass
Protected Overrides Sub Greeting()
Static j As Integer
j += 1
Console.WriteLine("Hello, Sub. For the " & j & "th time(s)")
End Sub
End Class
Public Module TestMain
Public Sub Main()
Dim o1 As I1
Dim o2 As I2
Dim o3 As BaseClass
Dim o4 As New SubClass
o1 = o4
o2 = o4
o3 = o4
o1.Test()
o2.Test()
o3.TheTest()
o3.AnotherTest()
End Sub
End Module
输出是
Hello, Base. For the 1th time(s)
Hello, Sub. For the 1th time(s)
Hello, Base. For the 2th time(s)
Hello, Sub. For the 2th time(s)
检查一下再贴哦