static void Main(string[] args) { { MovableObject obj = new MovableObject(); // left ILeft objLeft = obj; objLeft.Move(); // right IRight objRight = obj; objRight.Move(); } Console.WriteLine("-------------"); { // implementing both IMoving moving = new MovingObject(); //moving.Move(); // does not compile, ambiguous call // left ILeft movingLeft = moving; movingLeft.Move(); // right IRight movingRight = moving; movingRight.Move(); } Console.ReadKey(); }
static void Main(string[] args) { MovableObject obj = new MovableObject(); // left ILeft objLeft = obj; objLeft.Move(); // right IRight objRight = obj; objRight.Move(); // implementing both IMoving moving = new MovingObject(); // smoving.Move(); // does not compile, ambiguous call // left ILeft movingLeft = moving; movingLeft.Move(); // right IRight movingRight = moving; movingRight.Move(); }
static void Main(string[] args) { var moveableObj = new MoveableOject(); //moveableObj.Move(); ILeft left = moveableObj; left.Move(); ((ILeft)moveableObj).Move(); ((IRight)moveableObj).Move(); }