コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }