コード例 #1
0
ファイル: 11Generic.cs プロジェクト: pawlaczyk/C_sharp
        static void Main(string[] args)
        {
            // klasy i obiekty
            Animal spot = new Animal(15, 10, "Spot", "Woof");

            Console.WriteLine("{0} says {1}", spot.name, spot.sound);
            Console.WriteLine("Number of Animals " + Animal.getNumOfAnimals());
            Console.WriteLine(spot.toString());
            Console.WriteLine(spot.getSum(1.4, 2.7));
            //wyowlanie z wymuszenim kolejnscoi atrybutow po nazwie
            Console.WriteLine(spot.getSum(num2: 1.4, num1: 2.7));

            //object conditinale
            Animal grover = new Animal
            {
                name   = "Grover",
                height = 16,
                weight = 18,
                sound  = "Grrr"
            };

            Dog spike = new Dog();

            spike = new Dog(20, 15, "Spike", "Grr", "Chicken");
            Console.WriteLine(spike.toString());

            // polymorfizm
            Shape rect = new Rectangle(5, 5);
            Shape tri  = new Triangle(5, 5);

            Console.WriteLine("React Area: ", rect.area());
            Console.WriteLine("Tri Area: ", tri.area());

            Rectangle combRect = new Rectangle(5, 5) + new Rectangle(5, 5);

            Console.WriteLine("combReact area: " + combRect.area());


            // generic
            KeyValue <string, string> superman = new KeyValue <string, string>("", "");

            superman.key   = "Superman";
            superman.value = "Clark Kent";

            KeyValue <int, string> samsungTV = new KeyValue <int, string>(0, "");

            samsungTV.key   = 1234;
            samsungTV.value = "a 50 in Samsung TV";

            superman.showData();
            samsungTV.showData();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            // klasy i obiekty
            Animal spot = new Animal(15, 10, "Spot", "Woof");

            Console.WriteLine("{0} says {1}", spot.name, spot.sound);
            Console.WriteLine("Number of Animals " + Animal.getNumOfAnimals());
            Console.WriteLine(spot.toString());
            Console.WriteLine(spot.getSum(1.4, 2.7));
            //wyowlanie z wymuszenim kolejnscoi atrybutow po nazwie
            Console.WriteLine(spot.getSum(num2: 1.4, num1: 2.7));

            //object conditinale
            Animal grover = new Animal
            {
                name   = "Grover",
                height = 16,
                weight = 18,
                sound  = "Grrr"
            };

            Dog spike = new Dog();

            spike = new Dog(20, 15, "Spike", "Grr", "Chicken");
            Console.WriteLine(spike.toString());

            // polymorfizm
            Shape rect = new Rectangle(5, 5);
            Shape tri  = new Triangle(5, 5);

            Console.WriteLine("React Area: ", rect.area());
            Console.WriteLine("Tri Area: ", tri.area());

            Rectangle combRect = new Rectangle(5, 5) + new Rectangle(5, 5);

            Console.WriteLine("combReact area: " + combRect.area());
        }