您的位置:首页 > 其它

第一次写Blog

2007-05-08 17:31 281 查看
using System;

namespace Polymorphic
{
    interface IPoint
    {
        int X{get;set;}
        int Y{get;set;}
        double area();
    }
    class MyPoint : IPoint
    {
        private int x;
        private int y;
        public MyPoint(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
        public int X
        {
            get{return x;}
            set { x = value; }
        }
        public int Y
        {
            get { return y; }
            set { y = value; }
        }
        public double area()
        {
            return x * y;
        }
    }
    class Program
    {
        private static void printPoint(IPoint ip)
        {
            Console.WriteLine("x={0},y={1}", ip.X, ip.Y);
        }
        static void Main(string[] args)
        {
            MyPoint myPoint = new MyPoint(2, 3);
            Console.Write("My Point: ");
            printPoint(myPoint);
            Console.WriteLine(myPoint.area().ToString());
        }
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息