我有一些代碼來實現在C#接口實現與繼承在C#
public interface Intfc { void xyz();}
public class BaseClass : Intfc
{
public virtual void xyz()
{
Console.WriteLine("In Base Class");
}
}
public class Derived : BaseClass
{
public override void xyz()
{
Console.WriteLine("In Derived Class");
}
}
static void Main(string[] args)
{
Derived mc = new Derived();
mc.xyz(); //In Derived Class
((BaseClass)mc).xyz(); //In Base Class
((Intfc)mc).xyz(); //In Derived Class
Console.ReadKey();
}
接口,我需要在控制檯輸出爲Main()
中發表了。 實際結果爲
In Derived Class
In Derived Class
In Derived Class
我該如何達到預期的效果。
這是設計。你能給我們一個真實世界的例子嗎? – 2010-10-21 08:23:02