Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            DerivedClass instance = new DerivedClass();

            instance.Method();
            instance.Method1();
            instance.Method2();

            Console.WriteLine(new string('-', 55));

            BaseClass instance0 = instance as BaseClass; //видно только методы класса BaseClass

            instance0.Method();

            IInterface1 instance1 = instance as IInterface1; //видно только методы интерфейса IInterface1

            instance1.Method1();

            IInterface2 instance2 = instance as IInterface2; //видно только методы интерфейса IInterface2

            instance2.Method2();


            //Delay
            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            DerivedClass instance = new DerivedClass();

            instance.Method();
            instance.Method1();
            instance.Method2();

            Console.WriteLine(new string('-', 30));

            BaseClass instanse1 = instance as BaseClass;

            instanse1.Method();     //Другие два метода недоступны

            IInterface1 instance2 = instance as IInterface1;

            instance2.Method1();    //Другие два метода недоступны

            IInterface2 instance3 = instance2 as IInterface2;

            instance3.Method2();    //Другие два метода недоступны

            IInterface2 instance4 = instanse1 as IInterface2;

            instance4.Method2();

            Console.WriteLine(new string('-', 30));
            BaseClass   inst  = new BaseClass();
            IInterface2 inst1 = inst as IInterface2; //А вот это недопустимо, потому что даункаст без апкаста до этого?

            inst1.Method2();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            DerivedClass derivedClass = new DerivedClass();

            derivedClass.Method1();
            derivedClass.Method2();
            derivedClass.Method3();

            IInterface2 derivedClassUpToI2 = derivedClass;

            derivedClassUpToI2.Method1();
            derivedClassUpToI2.Method2();
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            DerivedClass dClass = new DerivedClass();


            dClass.Method1();
            dClass.Method2();
            dClass.Method3();

            IInterface2 dClassUp = dClass;

            dClassUp.Method1();
            dClassUp.Method2();

            Console.ReadKey();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            ConcreteClass instance = new ConcreteClass();

            instance.Method1();
            instance.Method2();

            IInterface1 instance1 = instance as IInterface1;

            instance1.Method1();

            IInterface2 instance2 = instance as IInterface2;

            instance2.Method1();
            instance2.Method2();

            // Delay
            Console.ReadKey();
        }
Ejemplo n.º 6
0
        static void Main()
        {
            ConcreteClass instance = new ConcreteClass();

            instance.Method1();
            instance.Method2();

            IInterface1 instance1 = instance as IInterface1;

            instance1.Method1();

            IInterface2 instance2 = instance as IInterface2;

            instance2.Method1();
            instance2.Method2();

                        // Delay.
                        Console.ReadKey();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            ConcreteClass instance = new ConcreteClass();

            instance.Method1();
            instance.Method2();

            IInterface1 instance1 = instance as IInterface1;

            instance1.Method1();

            IInterface2 instance2 = instance as IInterface2; //тут у нас есть доступ и к Method1 и к Method2

            instance2.Method1();                             // т.к IInterface2 наследуется от IInterface1
            instance2.Method2();

            //Delay
            Console.ReadKey();
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            ConcreteClass instance = new ConcreteClass();

            instance.Method1();
            instance.Method2();

            IInterface1 instance2 = instance as IInterface1;

            instance2.Method1();

            IInterface2 instance3 = instance2 as IInterface2;

            instance3.Method1();
            instance3.Method2();

            Console.WriteLine(new string('-', 30));

            ConcreteClass concreteClass = new ConcreteClass();
            IInterface2   interface2    = concreteClass as IInterface2;

            interface2.Method1();
            interface2.Method2();
        }