コード例 #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("请输入笔记本品牌:");
            string   brand = Console.ReadLine();
            NoteBook nb    = GetNoteBook(brand);

            nb.SayHello();
            Console.ReadKey();
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
 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)
         {
         }
     }
 }