标签:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { Console.WriteLine("你要什么电脑?"); string strs = Console.ReadLine(); Brand _bran = Faloy.GetBranName(strs); _bran.ShowBrand(); } } public abstract class Brand { public abstract void ShowBrand(); } public class Dell : Brand { public override void ShowBrand() { Console.WriteLine("Dell"); } } public class HP : Brand { public override void ShowBrand() { Console.WriteLine("HP"); } } public static class Faloy { public static Brand GetBranName(string str) { if (str == "dell") return new Dell(); else if (str == "hp") return new HP(); return null; } } }
标签:
原文地址:http://www.cnblogs.com/KevinDai/p/4553137.html