接口成员的访问

对于单重继承接口的访问,用户可以使用点运算符(.)来访问接口的方法成员,属性成员和事件成员。
对于多重继承接口的访问,要使用显示的类型转化来解决这种访问冲突
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace li2_5
{
     interface IPoint//接口成员的声明
    {
         int x { get; set; }
         int y { get; set; }
    }
    class Point:IPoint
    {
        private int pX;
        public int x
        {
            get { return pX; }
            set { pX = value; }
        }
        private int pY;
        public int y
        {
            get { return pY; }
            set { pY = value; }
        }
        public Point(int x, int y)
        {
            pX = x;
            pY = y;
        }
    }
    class Program
    {
        private static void OutPut(IPoint p)
        {
            Console.WriteLine("x={0},y={1}", p.x, p.y);
        }
        static void Main(string[] args)
        {
            Point p =new Point(15,30);
            Console.WriteLine("点的坐标为:");
            OutPut(p);
        }
    }
}

 

posted @ 2016-07-18 13:01  隐逸天涯  阅读(143)  评论(0编辑  收藏  举报