using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp1 { class Program { static void Main(string[] args) { Console.Write("请输入要电脑名称"); NoteBook noteBook = Factory(Console.ReadLine()); noteBook.Seyll(); Console.ReadKey(); } static NoteBook Factory(string str) { NoteBook noteBook = null; switch (str) { case "戴尔": noteBook = new Dell(); break; case "雷神": noteBook = new Asus(); break; default: break; } return noteBook; } } public abstract class NoteBook { public abstract void Seyll(); } public class Dell : NoteBook { public override void Seyll() { Console.WriteLine("我是戴尔电脑"); } } public class Asus : NoteBook { public override void Seyll() { Console.WriteLine("我是华硕电脑"); } } }