示例#1
0
        static void Main(string[] args)
        {
            // Make the COM collection.
            CarCollectionClass carColl = new CarCollectionClass();

            Console.WriteLine("Number of cars in initial collection: {0}", carColl.NumberOfCars());

            // iterate over cars.
            PrintCarCollection(carColl);

            // Add a car.
            CoCar newCar = carColl.AddCar("White", "Jetta", "Chucky", 55);

            // iterate over cars
            Console.WriteLine("\nCollection after adding a car.");
            PrintCarCollection(carColl);

            // Now remove car first 3 cars.
            Console.WriteLine("\nCollection after removing first 3 cars:");
            carColl.RemoveCar(1);
            carColl.RemoveCar(2);
            carColl.RemoveCar(3);

            // iterate over cars.
            PrintCarCollection(carColl);

            // Get car number 1.
            CoCar carOne = carColl.GetCar(1);

            Console.WriteLine("\nFirst Car has ID: {0}", carOne.CarID);

            // Now using raw enumeraor.
            Console.WriteLine("\nNow using IEnumerator");
            IEnumerator itfEnum = carColl.GetEnumerator();

            itfEnum.Reset();
            itfEnum.MoveNext();
            CoCarClass c = (CoCarClass)itfEnum.Current;

            Console.WriteLine("ID: {0} Make: {1} Color: {2} PetName: {3}", c.CarID,
                              c.Make, c.Color, c.PetName);
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** CoCar Client App *****");

            // Create the COM class using early binding.
            CoCar myCar = new CoCar();

            // Handle the BlewUp event.
            myCar.BlewUp += new __CoCar_BlewUpEventHandler(myCar_BlewUp);

            // Call the Create() method.
            myCar.Create(50, 10, CarType.BMW);

            // Set name of driver.
            IDriverInfo itf = null;

            itf            = (IDriverInfo)myCar;
            itf.DriverName = "Fred";
            Console.WriteLine("Drive is named: {0}", itf.DriverName);

            // Print type of car.
            Console.WriteLine("Your car is a {0}.", myCar.CarMake);
            Console.WriteLine();

            // Get the Engine and print name of a Cylinders.
            Engine eng = myCar.GetEngine();

            Console.WriteLine("Your Cylinders are named:");
            string[] names = (string[])eng.GetCylinders();
            foreach (string s in names)
            {
                Console.WriteLine(s);
            }
            Console.WriteLine();

            // Speed up car to trigger event.
            for (int i = 0; i < 5; i++)
            {
                myCar.SpeedUp();
            }
        }