示例#1
0
        /*1.	Constructor Linking/Constructor Initializers
         * Create a class called Game which has the following properties
         * •	Name:string
         * •	Price:decimal
         * •	ReleaseDate:DateTime
         * Create a constructor which has three parameters, one for each property
         * Through constructor linking create two other constructors which link to this main constructor.  These constructors are shown below.
         * public Game(string name, decimal price):this(name, price, DateTime.Now)
         * public Game() : this("", 0)
         * Add a ToString() method which displays all properties.
         */

        static void Main(string[] args)
        {
            //computer game object created
            ComputerGame g3 = new ComputerGame("Monopoly", 19.99m, DateTime.Now, "18");


            Console.WriteLine("{0,-15}{1,-15}{2,-25}{3,-15}", "Name", "Price", "Release Date", "PEGI Rating");

            //run display game method for object
            DisplayGame(g3);

            //run objcet to string method
            Console.WriteLine(g3.ToString());

            Console.WriteLine();
            Console.Write("Discount Price : ");
            //run Computer Game Discount method
            Console.WriteLine(g3.GetDiscountPrice());

            Console.WriteLine();

            //update price of object
            g3.UpdatePrice(12);

            Console.WriteLine();
            Console.WriteLine("{0,-15}{1,-15}{2,-25}{3,-15}", "Name", "Price", "Release Date", "PEGI Rating");

            DisplayGame(g3);
        }
        static void Main(string[] args)
        {
            //Game g1 =
            //   new Game("Monopoly", 19.99m, new DateTime(1970, 01, 31));

            //Game g2 =
            //   new Game() { Price = 10.99m, ReleaseDate = new DateTime(2000, 6, 15) };

            ComputerGame cg1 = new ComputerGame("Sonic", 29.99m, new DateTime(1990, 3, 15), "U");

            ComputerGame cg2 = new ComputerGame("Mario", 24.99m, new DateTime(1995, 11, 17), "7");

            //DisplayGame(g1);
            //DisplayGame(g2);
            DisplayGame(cg1);
            DisplayGame(cg2);
        }