コード例 #1
0
ファイル: Program.cs プロジェクト: tylerdav/inheritanceIntro
        static void Main(string[] args)
        {
            var myBike = new Zero();

            // i can still refrence the inherited properity
            myBike.Name             = "Zero";
            myBike.MainColor        = "Midnight Black";
            myBike.MaximumOccupancy = 2;

            var myTesla = new Tesla();

            myTesla.Name             = "Tesla";
            myTesla.MainColor        = "Space Gray";
            myTesla.MaximumOccupancy = 5;

            var myRam = new Ram();

            myRam.Name             = "Ram";
            myRam.MainColor        = "Rocket Red";
            myRam.MaximumOccupancy = 5;

            var myCessna = new Cessna();

            myCessna.Name             = "Cessna";
            myCessna.MainColor        = "Blue and White";
            myCessna.MaximumOccupancy = 8;

            myBike.Drive();
            myBike.Turn();
            myBike.stop();

            Console.WriteLine("-------------------------------------");

            myTesla.Drive();
            myTesla.Turn();
            myTesla.stop();

            Console.WriteLine("-------------------------------------");

            myRam.Drive();
            myRam.Turn();
            myRam.stop();

            Console.WriteLine("-------------------------------------");

            myCessna.Drive();
            myCessna.Turn();
            myCessna.stop();

            double price = 15.00;

            Console.WriteLine(price.ToString("C"));
        }
コード例 #2
0
        static void Main(string[] args)
        {
            var myBike = new Zero();

            //I can still reference the inherited class
            myBike.MainColor    = "Black";
            myBike.MaxOccupancy = 2;
            myBike.Name         = "Zero";

            var myTesla = new Tesla();

            myTesla.MainColor    = "Midnight Silver";
            myTesla.MaxOccupancy = 6;
            myTesla.Name         = "Tesla";

            var myRam = new Ram();

            myRam.MainColor    = "blue";
            myRam.Name         = "Ram";
            myRam.MaxOccupancy = 5;

            var myCessna = new Cessna();

            myCessna.MainColor    = "green";
            myCessna.Name         = "Cessna";
            myCessna.MaxOccupancy = 10;

            myBike.Drive();
            myTesla.Drive();
            myCessna.Drive();
            myRam.Drive();

            myBike.Turn("taking a left");
            myBike.Stop();

            myTesla.Turn("taking a right");
            myTesla.Stop();

            myRam.Turn("taking several wrong turns");
            myRam.Stop();

            myCessna.Turn("doing loops!");
            myCessna.Stop();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: jansenv/csharp
        static void Main(string[] args)
        {
            var myBike = new Zero();

            // I can still reference the inherited property
            myBike.MainColor    = "Black";
            myBike.MaxOccupancy = 2;

            var myTesla = new Tesla();

            myTesla.MainColor    = "Midnight Silver";
            myTesla.MaxOccupancy = 6;

            var myRam = new Ram();

            myRam.MainColor = "Black as midnight on a moonless night";

            var myCessna = new Cessna();

            myCessna.MainColor = "Drug runner White";

            myBike.Drive();
            myBike.Turn();
            myBike.Stop();

            myTesla.Drive();
            myTesla.Turn();
            myTesla.Stop();

            myRam.Drive();
            myRam.Turn();
            myRam.Stop();

            myCessna.Drive();
            myCessna.Turn();
            myCessna.Stop();

            Console.WriteLine(myTesla);

            double price = 15.50;

            Console.WriteLine(price.ToString("C"));
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var myBike = new Zero();

            // I can still refer to the inherited property
            myBike.MainColor     = "Black";
            myBike.MaxOccupancey = 2;

            var myTesla = new Tesla();

            myTesla.MainColor     = "Midnight Silver";
            myTesla.MaxOccupancey = 6;

            var myRam = new Ram();

            myRam.MainColor     = "Candy Apple Red";
            myRam.MaxOccupancey = 5;

            var myCessna = new Cessna();

            myCessna.MainColor     = "Olive Green";
            myCessna.MaxOccupancey = 4;

            myBike.Drive();
            myBike.Turn();
            myBike.Stop();
            myTesla.Drive();
            myTesla.Turn();
            myTesla.Stop();
            myRam.Drive();
            myRam.Turn();
            myRam.Stop();
            myCessna.Drive();
            myCessna.Turn();
            myCessna.Stop();
        }