【发布时间】:2016-10-14 06:19:56
【问题描述】:
我有两节课
public class A
{
public A(string N)
{
Name = N;
}
public string Name { get; set; }
public void GetName()
{
Console.Write(Name);
}
}
public class B : A
{
public B(string N) : base(N)
{
}
public new void GetName()
{
Console.Write(new string(Name.Reverse().ToArray()));
}
}
我创建了一个新对象B,我想从A 调用GetName,从B 调用GetName
B foo = new B("foo");
foo.GetName(); // output "oof"
预期输出"foooof"
我已经尝试过public new void GetName() : base,但编译失败
【问题讨论】:
标签: c# class inheritance