【发布时间】:2011-06-22 17:48:24
【问题描述】:
class Program
{
static void Main(string[] args)
{
List<A> myList = new List<A> {new A(), new B(), new C()};
foreach (var a in myList)
{
Render(a);
}
Console.ReadKey();
}
private static void Render(A o)
{
Console.Write("A");
}
private static void Render(B b)
{
Console.Write("B");
}
private static void Render(C c)
{
Console.Write("C");
}
}
class A
{
}
class B : A
{
}
class C : A
{
}
输出为:AAA
是否有可能以某种方式使用方法重载,以便输出为:ABC?
【问题讨论】:
标签: c# .net polymorphism overloading