日期:2014-05-17  浏览次数:20894 次

程序出错,大家帮帮忙!
static void Main(string[] args)
        {
            Robot r1 = new Robot();
            r1.Name = "智能1号";
            Robot r2 = new Robot();
            r2.Name = "智能2号";
            Robot r;
            int i = 0;
            Console.WriteLine("请选择机器人:1→智能1号,2→智能2号");
            while (i == 0)
            {
                string number = Console.ReadLine();
                if (number == "1")
                {
                    r = r1;
                    i = 1;
                }
                else if (number == "2")
                {
                    r = r2;
                    i = 1;
                }
                else
                {
                    Console.WriteLine("输入有误,请重新输入。");
                }
            }                     
            r.SayHello();
            while (true)
            {
                string str = Console.ReadLine();
                r.Speak(str);
            }

            Console.ReadKey();
        }

程序如上,Robot是我定义的一个类,上面这段程序就是