Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Tennis  a1 = new Inventory();
            ITennis a2 = new Inventory();

            Console.WriteLine($"It is class'es method: {a1.Field(4, 5)}");
            Console.WriteLine($"It is Interface: {a2.Field(4, 5)}");
            Console.WriteLine();

            Bars bar1 = new Bars("blue");

            Console.WriteLine($"bar1 is Bars? {bar1 is Bars}");
            bar1.ToString();
            Mats mat1 = new Mats("yellow");

            Console.WriteLine($"mat1 is Bars? {mat1 is Bars}");
            Console.WriteLine($"mat1 is Mats? {mat1 is Mats}");
            Bench bench1 = new Bench("red");

            Console.WriteLine($"bench1 is Inventory? {bench1 is Inventory}");
            Console.WriteLine($"bench1 is Bench? {bench1 is Bench}");
            Console.WriteLine();

            Mats      mat2 = new Mats("gray");
            Inventory a3   = mat2 as Inventory;

            Console.WriteLine($"a3 is Inventory? {a3 is Inventory}");
            Console.WriteLine($"a3 is Mats? {a3 is Mats}");
            Console.WriteLine($"mat2 is Inventory? {mat2 is Inventory}");
            Console.WriteLine($"mat2 is Mats? {mat2 is Mats}");
            Console.WriteLine("Something about mat2");
            Console.WriteLine(mat2.ToString());
            Console.WriteLine("Something about a3");
            Console.WriteLine(a3.ToString());
            Console.WriteLine();

            Inventory    b1 = new Inventory();
            Ball         b2 = new Ball("white", 10);
            BallOfBasket b3 = new BallOfBasket("green", 15);

            ITennis[] arr = new ITennis[3];
            arr[0] = b1;
            arr[1] = b2;
            arr[2] = b3;
            foreach (ITennis x in arr)
            {
                Print.IAmPrinting(x);
            }

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            Bench p = obj as Bench;

            if (p as Bench == null)
            {
                return(false);
            }

            return(p.length == this.length && p.width == this.width);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Bench bench1 = new Bench {
                name = "bench1", length = 23, mass = 15, width = 3
            };

            Console.WriteLine(bench1.Cost(2));

            Tennis tennis1 = new Tennis {
                number = 3, name = "tennis1", mass = 10, radius = 5
            };

            Console.WriteLine(tennis1.Lifetime(5));             // методы абстрактного класса


            tennis1.ToString();

            set_of_classes ball1 = new set_of_classes();

            //cube cub = new cube();
            //cub.Print();
            Class2 cl1 = new Class2();                              // объект для одноименный метод в интерфейсе и в абстрактном классе



            Console.WriteLine(((Interface1)cl1).SUM(2, 3));         // одноименный метод в интерфейсе и в абстрактном классе

            Printer pr = new Printer();

            Description[] arr = new Description[3] {
                bench1, tennis1, ball1
            };
            pr.IAmPrinting(arr[0]);
            pr.IAmPrinting(arr[1]);
            pr.IAmPrinting(arr[2]);

            Console.ReadKey();
        }