作业帮 > 综合 > 作业

请按照下列要求,编写一个C#控制台应用程序.

来源:学生作业帮 编辑:搜搜考试网作业帮 分类:综合作业 时间:2024/06/11 06:10:19
请按照下列要求,编写一个C#控制台应用程序.
请按照下列要求,编写一个C#控制台应用程序.
class Instrument
    {
        protected string _name { get; set; }
        protected string _action { get; set; }
        public virtual string Play()
        {
            return string.Format("{0}是{1}的", _name, _action);
        }
    }
    class Piano : Instrument
    {
        public Piano()
        {
            _name = "钢琴";
            _action = "弹";
        }
    }
    class Violin : Instrument
    {
        public Violin()
        {
            _name = "小提琴";
            _action = "拉";
        }
    }
    class Horn : Instrument
    {
        public override string Play()
        {
            return "喇叭是吹的";
        }
    }static void Main(string[] args)
        {
            Instrument a = new Piano();
            Instrument b = new Violin();
            Instrument c = new Horn();
            Console.WriteLine(a.Play());
            Console.WriteLine(b.Play());
            Console.WriteLine(c.Play());
            Console.WriteLine("按回车退出...");
            Console.Read();
        }
再问: 有错误,运行不了。