Код: Выделить всё
public interface IA
{
int doA();
}
public interface IB
{
int doB();
}
class Impl1: IA, IB
{
int doA() => 1;
int doB() => 2;
}
class Impl2: IA, IB
{
int doA() => 3;
int doB() => 4;
}
Код: Выделить всё
IA it = default;
if (condition)
it = new Impl1()
else
it = new Impl2();
it.doA() // all good
((IB)it).doB() // I know this is safe because I know that it will always be an IB, but the compiler doesn't help me here
Подробнее здесь: https://stackoverflow.com/questions/797 ... in-c-sharp
Мобильная версия