我用C#建了一个项目,
内建了一个类:Point.cs:
namespace Classes
{
    class Point
    {
        private int x, y;
        public double DistanceTo(Point other)
        {
            int xDiff =this.x-other.x;
            int yDiff=this.y-other.y;

            return Math.Sqrt(xDiff * xDiff + yDiff * yDiff);
        }
        public Point()
        {
            this.x=-1;
            this.y=-1;
            Console.WriteLine("default constructor called");
        }
        public Point(int x, int y)
        {
            Console.WriteLine("x:{0},y:{1}", x, y);
        }
        
    }
}
接着建了一个program.cs:
namespace Classes
{
    class Program
    {
        static void Entrance()
        {
            
            Point origin = new Point();
            Point bottomRight = new Point(1024, 1280);
            
            double distance = origin.DistanceTo(bottomRight);
            Console.WriteLine("Distance is : {0}", distance);
        }        static void Main(string[] args)
        {
            try
            {
                Entrance();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }
    }
}
打开时,得出的结果distanse却是0,我自己看几遍,发现DistanceTo中
int xDiff =this.x-other.x;
int yDiff=this.y-other.y;
发现后面的other.x和other.y有跟没有都一样呢,
我实在不明白为什么?如果因为x,y是Point类的私有字段的话,不能访问的话,它应该调试错误呀,可是可以调试运行,得到
的是2的平方差,可是没有错的话,它应该给other.x和other.y附值呀
希望大家帮我解答解答,非常谢谢!!!