Files
Csharp/C#进阶/Lesson7_List练习/Program.cs
T

63 lines
1.4 KiB
C#
Raw Normal View History

2025-10-13 19:38:59 +08:00
namespace Lesson7_List练习
{
#region 第二题
abstract class Monster
{
public static List<Monster> monsters = new List<Monster>();
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<int> l1 = new List<int>();
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
}
}
}