using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12
{
    interface IPoint
    {
        int x { get; set; }//定义成员变量x,它含有读写抽象访问
        int y { get; set; }
    }
    class Point :IPoint
    {
        private int px;
        private int py;
        public Point(int x,int y)//构造函数
        {
            px = x;
            py = y;
        }
        public int x//接口属性实现
        {
            get { Console.WriteLine("\n调用接口读取数据px"); return px; }
            set { Console.WriteLine("\n调用接口写入数据px"); px = value; }

        }
        public int y//接口属性实现
        {
            get { Console.WriteLine("调用接口读取数据py"); return py; }
            set { Console.WriteLine("\n调用接口写入数据px"); py = value; }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Point p = new Point(4, 30);
            Console.Write("新创建的point点的坐标是:");
            p.x = 666;

            Console.WriteLine("x={0},y={1}",p.x,p.y);
            Console.ReadKey();

        }
    }
}

声明接口IPoint描述一个点的 坐标并实现该接口

相关文章:

  • 2022-01-23
  • 2022-02-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-03
  • 2021-08-16
  • 2021-07-12
  • 2021-09-23
  • 2022-12-23
  • 2021-05-15
相关资源
相似解决方案