扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:LoveCherry 来源:博客园 2007年12月4日
关键字:
以下是引用片段: public override void Add(Element element) { serviceList.Add((GameService)element); } public override void Remove(Element element) { serviceList.Remove((GameService)element); } public override void Display() { Console.WriteLine(string.Format("{0}{1}({2}){3}", new string('+', 10), name, serverIP, new string('+', 10))); foreach (Element element in serviceList) { element.Display(); } } public override void Start() { serviceList.Sort(); Console.WriteLine("=============Starting the whole " + name + "============="); for (int i = 0; i < serviceList.Count; i++ ) { serviceList[i].Start(); } Console.WriteLine("=============The whole " + name + " started============="); } public override void Stop() { Console.WriteLine("=============Stopping the whole " + name + "============="); for (int i = serviceList.Count -1; i >= 0; i--) { serviceList[i].Stop(); } Console.WriteLine("=============The whole " + name + " stopped============="); } } class GameArea : Element { private List serverList = new List(); public GameArea(string name) : base(name) { } public override void Add(Element element) { serverList.Add((GameServer)element); } public override void Remove(Element element) { serverList.Remove((GameServer)element); } public override void Display() { Console.WriteLine(new string('=',20)); Console.WriteLine(" " + name); Console.WriteLine(new string('=', 20)); foreach (Element element in serverList) { element.Display(); } } public override void Start() { Console.WriteLine("=============Starting the whole " + name + "============="); foreach (Element element in serverList) { element.Start(); } Console.WriteLine("=============The whole " + name + " started============="); } public override void Stop() { Console.WriteLine("=============Stopping the whole " + name + "============="); foreach (Element element in serverList) { element.Stop(); } Console.WriteLine("=============The whole " + name + " stopped============="); } } } |
代码执行结果如下图:
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者