using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
class OneBase
{
protected virtual string GetName()
{
return "OneBase";
}
public void PrintName()
{
Console.WriteLine(GetName());
}
}
class A : OneBase
{
protected override string GetName()
{
return "A";
}
}
class B : OneBase
{
protected override string GetName()
{
return "B";
}
}
static void Main(string[] args)
{
List<OneBase> baseLst = new List<OneBase>();
B b = new B();
baseLst.Add(b);
A a = new A();
baseLst.Add(a);
foreach (OneBase o in baseLst)
{
o.PrintName();
}
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
class OneBase
{
protected virtual string GetName()
{
return "OneBase";
}
public void PrintName()
{
Console.WriteLine(GetName());
}
}
class A : OneBase
{
protected override string GetName()
{
return "A";
}
}
class B : OneBase
{
protected override string GetName()
{
return "B";
}
}
static void Main(string[] args)
{
List<OneBase> baseLst = new List<OneBase>();
B b = new B();
baseLst.Add(b);
A a = new A();
baseLst.Add(a);
foreach (OneBase o in baseLst)
{
o.PrintName();
}
Console.ReadLine();
}
}
}
本文转自 xchsp 51CTO博客,原文链接:http://blog.51cto.com/freebird/687319,如需转载请自行联系原作者