C#中類的使用舉例

iamzxf發表於2015-03-09


using System;

namespace CSharp.chapter01
{
    public class Point
    {
        public int x, y;
        public Point(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }
    class PointTest
    {
        static void Main(string[] args)
        {
            Point p1 = new Point(0, 0);
            Point p2 = new Point(10, 20);
            Console.WriteLine("兩個點的座標為:");
            Console.WriteLine("p1: x=" + p1.x + ",y=" + p1.y);
            Console.WriteLine("p2: x=" + p2.x + ",y=" + p2.y);
            Console.ReadKey();
        }
    }
}



相關文章