static void Main(string[] args) { DerivedClass derivedClass = new DerivedClass(); derivedClass.Method1(); derivedClass.Method2(); derivedClass.Method3(); IInterface2 derivedClassUpToI2 = derivedClass; derivedClassUpToI2.Method1(); derivedClassUpToI2.Method2(); }
static void Main(string[] args) { DerivedClass dClass = new DerivedClass(); dClass.Method1(); dClass.Method2(); dClass.Method3(); IInterface2 dClassUp = dClass; dClassUp.Method1(); dClassUp.Method2(); Console.ReadKey(); }
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(); }
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(); }
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(); }
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(); }