コード例 #1
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();
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Anil1111/Education
        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();
        }