Esempio n. 1
0
        static void Main(string[] args)
        {
            ConcreteClass concreteClass = new ConcreteClass();

            //Upcast needed
            IInterface1 interface1 = concreteClass as IInterface1;

            interface1.Method();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            ConcreteClass concreteClass = new ConcreteClass();

            concreteClass.Method();

            IInterface1 interface1 = concreteClass as IInterface1;

            interface1.Method();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            ConcreteClass instance = new ConcreteClass();

            IInterface1 instance1 = instance as IInterface1;

            instance1.Method();

            IInterface2 instance2 = instance as IInterface2;

            instance2.Method();

            Console.ReadKey();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            DerivedClass instance = new DerivedClass();

            //instance. - не видит методов интерфейса

            //Для этого апкастим к базовому интерфейсному типу
            IInterface1 instance1 = instance as IInterface1;

            instance1.Method();

            IInterface2 instance2 = instance as IInterface2;

            instance2.Method();
        }
Esempio n. 5
0
        static void Main()
        {
            ConcreteClass instance = new ConcreteClass();
                        //instance.Method ();

                        IInterface1 instance1 = instance as IInterface1;

            instance1.Method();

            IInterface2 instance2 = instance as IInterface2;

            instance2.Method();

                        // Delay.
                        Console.ReadKey();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            ConcreteClass instance = new ConcreteClass();
            // instance.         ----Ничего не видно

            IInterface1 instance1 = instance as IInterface1;

            instance1.Method();//один метод //ОН ВИДЕН ПОТОМУ, ЧТО ВСЕ МЕТОДЫ В ИНТЕРФЕЙСАХ ПО УМОЛЧАНИЮ PUBLIC!!!

            IInterface2 instance2 = instance as IInterface2;

            instance2.Method();
            instance2.Method();//другой метод  //ОН ВИДЕН ПОТОМУ, ЧТО ВСЕ МЕТОДЫ В ИНТЕРФЕЙСАХ ПО УМОЛЧАНИЮ PUBLIC!!!

            //Delay
            Console.ReadKey();
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            DerivedClass instance = new DerivedClass();
            // instance.   -- //На экземпляре не видим private методов интерфейсов!

            //Приведем экземпляр класса DerivedClasss - instance, к базовому интервейсному типу IInterface1
            IInterface1 instance1 = instance as IInterface1;

            instance1.Method();

            IInterface2 interface2 = instance as IInterface2;

            interface2.Method();

            //Но мы можем увидить методы, которые public
            instance.Method3();
            //Delay
            Console.ReadKey();
        }