示例#1
0
        static void FunWithClassTypes()
        {
            Console.WriteLine("***** Fun with Class Types *****\n");

            //  创建一个叫Chuck的Car,速度为10MPH
            Car chuck = new Car();

            chuck.PrintState();
            Console.WriteLine();

            //  创建一个叫Mary的Car,速度为0MPH
            Car mary = new Car("Mary");

            mary.PrintState();
            Console.WriteLine();

            //  创建一个叫Daisy的Car,速度为75MPH
            Car daisy = new Car("Daisy", 75);

            daisy.PrintState();

            //  分配和设置Car对象
            Car myCar = new Car();

            myCar.petName   = "Henry";
            myCar.currSpeed = 10;

            //  将Car加速几次,然后就输出新的状态
            for (int i = 0; i < 10; i++)
            {
                myCar.SpeedUp(5);
                myCar.PrintState();
            }
            Console.WriteLine();

            Console.WriteLine("***** Fun with class Types *****\n");

            //创建Motorcycle
            Motorcycle c = new Motorcycle(5);

            c.SetDriveName("Tiny");
            c.PopAWheely();
            Console.WriteLine("Rider name is {0}", c.driverName);
            Console.WriteLine();
        }