namespace Lesson7_List练习 { #region 第二题 abstract class Monster { public static List monsters = new List(); public Monster() { monsters.Add(this); } public abstract void Atk(); } class Boss: Monster { public override void Atk() { Console.WriteLine("Boss攻击"); } } class Goblin : Monster { public override void Atk() { Console.WriteLine("哥布林攻击"); } } #endregion class Program { static void Main(string[] args) { #region 第一题 List l1 = new List(); for (int i = 10; i > 0; i--) { l1.Add(i); } l1.RemoveAt(4); for (int i = 0; i < l1.Count; i++) { Console.WriteLine(l1[i]); } Console.WriteLine("_______________________________"); #endregion #region 第二题 Monster m1 = new Boss(); Monster m2 = new Goblin(); Boss b = new Boss(); Goblin g = new Goblin(); for (int i = 0;i < Monster.monsters.Count;i++) { Monster.monsters[i].Atk(); } #endregion } } }