原程序是:
using System;
class Point
{
public Point()
{
this.x = 1;
this.y = 1;
}
public Point(int x, int y)
{
this.x = x;
this.y = y;
}
public double Distance(Point other)
{
int xDiff = this.x - other.x;
int yDiff = this.y - other.y;
return Math.Sqrt(xDiff * xDiff + yDiff * yDiff);
}
private int x,y;
}
class Program
{
static void Main()
{
Point origin = new Point();
Point bottom = new Point(1, 2);
double distance = origin.Distance(bottom);
Console.WriteLine("Distance is:{0}", distance);
}
}
本人刚学,还在模仿阶段,请指教。