示例#1
0
        static void ClassDefault()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("=> Class Default value");

            Car c = new Car {
                Name = "Mike", Speed = 50, Color = "Grey"
            };

            c.Display();

            Garage g = new Garage();

            g.Auto = c;
            Console.WriteLine($"Number of Cars: {g.NumberofCars}");

            try
            {
                Console.WriteLine($"Car Name: {g.Auto.Name}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Error: {e.Message}");
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine("***Fun with Automatic properties ***\n");

            Car c = new Car();

            c.PetName = "Ford";
            c.Color   = "Red";
            c.Speed   = 240;
            c.Display();

            Garage g = new Garage();

            g.MyAuto = c;
            Console.WriteLine("Number of cars in garage is {0}", g.NumberOfCars);
            Console.WriteLine("Your car is named: {0}", g.MyAuto.PetName);

            Console.ReadLine();
        }