Пример #1
0
        private static void Main(string[] args)
        {
            // различные варианты присвоения значений переменным, имеющим тип интерфейса

            // вариант 1
            MyClass myClass = new MyClass();

            myClass.Print();
            IMyInterface myInterface = (IMyInterface)myClass;

            myInterface.Print();
            Console.WriteLine(new string('-', 30));
            // вариант 2
            IMyAnotherInterface myAnotherInterface = new MyClass();

            // вариант 3
            INewInterface myNewInterface = myClass as INewInterface;

            myNewInterface.Display();
            Console.WriteLine(new string('-', 30));
            MyDerivedClass myDerivedClass = new MyDerivedClass();

            myDerivedClass.Print();
            Console.ReadKey();
        }