添加Lesson7
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user