知识点一:基本概念
知识点二:基本实现
#region 知识点二基本实现
class GameObject
{
}
class Player : GameObject
{
public void PlayerAtk()
{
Console.WriteLine("玩家攻击");
}
}
class Monster : GameObject
{
public void PlayerAtk()
{
Console.WriteLine("怪物攻击");
}
}
class Boss : GameObject
{
public void PlayerAtk()
{
Console.WriteLine("Boss攻击");
}
}
#endregion
internal class Program
{
static void Main(string[] args)
{
//里氏替换原则 用父类容器 装载子类对象
GameObject player=new Player();
GameObject monster=new Monster();
GameObject boss=new Boss();
GameObject[] objects=new GameObject[] {new Player(),new Monster(),new Boss()};
知识点三:is和as