我有一個錯誤,並在我的書中搜索了答案,並觀看了關於這個特定主題的教程。大的差距,表示另一I類新增稱爲Point
我不明白我爲什麼得到CS0120
class Program
{
private static Point another;
static void Main(string[] args)
{
Point origin = new Point(1366, 768);
Point bottomRight = another;
double distance = origin.DistanceTo(bottomRight);
Console.WriteLine("Distance is: {0}", distance);
Console.WriteLine("Number of Point objects: {0}", Point.ObjectCount());
}
}
class Point {
private int x, y;
private int objectCount = 0;
public Point()
{
this.x = -1;
this.y = -1;
objectCount++;
}
public Point(int x, int y)
{
this.x = x;
this.y = y;
objectCount++;
}
public double DistanceTo(Point other)
{
int xDiff = this.x - other.x;
int yDiff = this.y - other.y;
double distance = Math.Sqrt((xDiff * xDiff) + (yDiff * yDiff));
return distance;
}
public static int ObjectCount()
{
**return objectCount;**
}
}
歡迎來到我們的社區。請注意,您必須發佈一個很好的問題才能獲得其他人的幫助。從您的代碼中移除不必要的部分並簡化它,當然不要改用空格。 如果你希望別人花時間處理你的問題,你必須成爲第一個關心和花時間的人 –