コード例 #1
0
        static void Main(string[] args)
        {
            int[,] values = { { 1, 2, 3 },
                              { 4, 5, 6 } };

            int    l  = values.Length;
            int    l1 = values.GetLength(0);
            int    l2 = values.GetLength(1);
            Class1 c1 = new Class1();
            Class1 c2 = new Class2();
            Class1 c3 = new Class3();
            Class1 c4 = new Class4();

            c1.Method1();
            c1.Method2();
            Console.WriteLine();
            c2.Method1();
            c2.Method2();
            Console.WriteLine();

            c3.Method1();
            c3.Method2();
            Console.WriteLine();

            c4.Method1();
            c4.Method2();
            Console.ReadLine();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Test-1a/Inheritance
        static void Main(string[] args)
        {
            //FGH
            IVehicle vehicle     = new Vehicle("ABC123");
            IVehicle bike        = new Bicycle("BBB333zGH45");
            IVehicle fuelVehicle = new FuelVehicle("AAA444", 100)   //skickar regnummer o fuelcapacity till constr
            {
                FuelLevel = 50
            };


            Console.WriteLine(vehicle.Drive(150));
            Console.WriteLine("------------------");
            var result = bike.Drive(8);

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

            Class1 classobj = new Class3()
            {
                Name   = "Kalle",
                Age    = 12,
                Adress = "Blahavägen 3"
            };

            FuelCar fuelCar = new FuelCar("FFF777", 150)
            {
                FuelLevel = 50
            };

            Console.WriteLine(fuelCar.Milage);
            Console.WriteLine(fuelCar.Drive(20));
            Console.WriteLine(fuelCar.Drive(40));
            Console.WriteLine(fuelCar.Milage);
        }
コード例 #3
0
        static void Main(string[] args)
        {
            var class1 = new Class1();
            var class2 = new Class2();
            var class3 = new Class3();

            int value = 1;

            Console.WriteLine("{0}: {1}", nameof(class1), class1.SomeMethod(value));
            Console.WriteLine("{0}: {1}", nameof(class2), class2.SomeMethod(value));
            Console.WriteLine("{0}: {1}", nameof(class3), class3.SomeMethod(value));
            Console.WriteLine("{0}: {1}", nameof(class1), (class1 as Interface1).SomeMethod(value));
            Console.WriteLine("{0}: {1}", nameof(class1), (class1 as Interface2).SomeMethod(value));
            Console.WriteLine("{0}: {1}", nameof(class3), (class3 as Interface1).SomeMethod(value));
            Console.WriteLine("{0}: {1}", nameof(class3), (class3 as Interface2).SomeMethod(value));
        }