コード例 #1
0
 public Garage(Car1 car, int number)
 {
     MyAuto       = car;
     NumberOfCars = number;
 }
コード例 #2
0
        static void Main()
        {
            #region Title
            ChangeConsoleColor();
            Console.WriteLine("*******Fun with Encapsulation*******\n");
            DefaultConsoleColor();
            #endregion

            #region Encapsulation
            ChangeConsoleColor();
            Console.WriteLine("\nUnderstanding Encapsulation\n");
            DefaultConsoleColor();

            book miniNovel = new book();
            miniNovel.NumberOfPages = 30_000_000;
            Console.WriteLine("{0:0,0}", miniNovel.NumberOfPages);
            #endregion

            #region Accessors and Mutators
            ChangeConsoleColor();
            Console.WriteLine("\nAccessors and Mutators\n");
            DefaultConsoleColor();

            Employee emp = new Employee("Tushar", 1415, 500_000);
            emp.GiveBonus(100_000);
            emp.DisplayStats();

            emp.Name = "Tush";
            Console.WriteLine($"\nName : {emp.Name}");

            Employee emp2 = new Employee();
            emp2.Name = "Tushar the Great Warrior";

            Employee joe = new Employee("Joe", 23, 1416, 3_00_000, "CSJPM7004B");
            joe.Age++;
            joe.DisplayStats();
            #endregion

            #region Revisiting the static keyword
            ChangeConsoleColor();
            Console.WriteLine("\nRevisiting the static keyword\n");
            DefaultConsoleColor();

            SavingsAccount s1 = new SavingsAccount();
            Console.WriteLine(SavingsAccount.InterestRate);
            #endregion

            #region Automatic Properties
            ChangeConsoleColor();
            Console.WriteLine("\nAutomatic Properties\n");
            DefaultConsoleColor();

            // Make a Car
            Car1 c = new Car1();
            c.PetName = "Bugatti";
            c.Speed   = 440;
            c.Color   = "Black-Orange";
            c.DisplayStats();
            #endregion

            #region Automatic Properties and Default Values
            ChangeConsoleColor();
            Console.WriteLine("\nAutomatic Properties and Default Values\n");
            DefaultConsoleColor();

            // Put a car in the garage
            Garage g = new Garage();
            g.MyAuto = c;
            Console.WriteLine($"No. of Cars : {g.NumberOfCars}");
            Console.WriteLine($"Your car is named : {g.MyAuto.PetName}");
            #endregion

            Console.ReadLine();
        }