static void Main(string[] args) { Console.WriteLine("请输入笔记本品牌:"); string brand = Console.ReadLine(); NoteBook nb = GetNoteBook(brand); nb.SayHello(); Console.ReadKey(); }
public static NoteBook GetNoteBook(string brand) { NoteBook nb = null; switch (brand) { case "Lenovo": nb = new Lenovo(); break; case "IBM": nb = new IBM(); break; case "Acer": nb = new Acer(); break; case "DELL": nb = new DELL(); break; } return(nb); }
public static NoteBook GetBook(string brand) { NoteBook nb = null; switch (brand) { case "HP": nb = new HP(); break; case "Lenovo": nb = new Lenovo(); break; case "IBM": nb = new IBM(); break; } return(nb); }
static void Main(string[] args) { while (true) { Console.WriteLine("请输入笔记本品牌:"); string brand = Console.ReadLine(); try { if (brand.Equals("end", StringComparison.OrdinalIgnoreCase)) { break; } NoteBook nb = GetBook(brand); nb.SayHello(); Console.ReadKey(); } catch (Exception) { } } }