日期:2014-05-18  浏览次数:20809 次

在进行调试时,输入了数据,但在输出结果的时候,窗口突然消失了!但用逐步调试的时候却没有什么问题?求解!!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Class
{
  class Program
  {
  static void Main(string[] args)
  {
  int x2 = int.Parse(Console.ReadLine());
  int y2 = int.Parse(Console.ReadLine());
  Point p1 = new Point();
  Point p2 = new Point(x2, y2);
  double distance = p1.DistanceTo(p2);
  Console.WriteLine(distance);

  }
  }
}











新建一个类



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Class
{
  class Point
  {
  private int x;
  private int y;

  public Point()
  {
  x = -1;
  y = -1;
  }
  public Point(int z, int h)
  {
  x = z;
  y = h;
  }
  public double DistanceTo(Point p)
  {
  int xdis = x - p.x;
  int ydis = y - p.y;
  return Math.Sqrt(xdis * xdis + ydis * ydis);
  }
  }
}


------解决方案--------------------
Console.WriteLine(distance);
Console.ReadKey();