出个小问题,看谁能做出

Ninputer 2004-03-19 03:49:00
谁能把这段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)

检查一下再贴哦
...全文
45 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ninputer 2004-03-21
  • 打赏
  • 举报
回复
算了,结了。看来上次调查都是说大话的。
Ninputer 2004-03-20
  • 打赏
  • 举报
回复
还不错。
怎么只有一个人翻?上次我做掉查“VB.NET什么地方不如C#”的时候,每个人都说C#强大,都说没有VB.NET能写出而C#不能写出的程序,怎么现在都不动了呢?
neilwang 2004-03-19
  • 打赏
  • 举报
回复
using System;

namespace CSDN
{
public interface I1
{
void Test();
}

public interface I2
{
void Test();
}

public class BaseClass : I1, I2
{
public void TheTest()
{
this._Greeting();
}

void I1.Test()
{
this.TheTest();
}

public void AnotherTest()
{
this.Greeting();
}

void I2.Test()
{
this.AnotherTest();
}

private void _Greeting()
{
i += 1;
Console.WriteLine("Hello, Base. For the " + i + "th time(s)");
}

static int i = 0;
protected virtual void Greeting()
{
this._Greeting();
}
}

public class SubClass : BaseClass
{
static int j = 0;
protected override void Greeting()
{
j += 1;
Console.WriteLine("Hello, Sub. For the " + j + "th time(s)");
}
}

/// <summary>
/// Summary description for TestMain.
/// </summary>
class TestMain
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
I1 o1;
I2 o2;
BaseClass o3;
SubClass o4 = new SubClass();

o1 = o4;
o2 = o4;
o3 = o4;

o1.Test();
o2.Test();
o3.TheTest();
o3.AnotherTest();
}
}
}
Ninputer 2004-03-19
  • 打赏
  • 举报
回复
有点难度的,谁来挑战一下
Bob 2004-03-19
  • 打赏
  • 举报
回复
有点头晕~

http://www.csdn.net/develop/Read_Article.asp?id=25354
coudoufu 2004-03-19
  • 打赏
  • 举报
回复
up
看着end就头痛
littlechang 2004-03-19
  • 打赏
  • 举报
回复
UP

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧