出于某种原因,这会编译,但最后会出现错误,我不知道为什么。代码的第一部分是显示文本文件中正常工作的表格,第二部分没有。
我认为它甚至没有到达 Console.WriteLine 位,这是一种检查它是否存在的方法。谁能明白为什么?
谢谢你提供的所有帮助!
class Program
{
static void Main(string[] args)
{
List<float> inputList = new List<float>();
TextReader tr = new StreamReader("c:/users/tom/documents/visual studio 2010/Projects/DistanceCalculator3/DistanceCalculator3/TextFile1.txt");
String input = Convert.ToString(tr.ReadToEnd());
String[] items = input.Split(',');
Console.WriteLine("Point Latitude Longtitude Elevation");
for (int i = 0; i < items.Length; i++)
{
if (i % 3 == 0)
{
Console.Write((i / 3) + "\t\t");
}
Console.Write(items[i]);
Console.Write("\t\t");
if (((i - 2) % 3) == 0)
{
Console.WriteLine();
}
}
Console.WriteLine();
Console.WriteLine();
// Ask for two bits of data which are then stored in Longtitude, Latitude and Elevation
Console.WriteLine("Please enter the two points that you wish to know the distance between:");
string point = Console.ReadLine();
string[] pointInput = point.Split(' ');
int pointNumber = Convert.ToInt16 (pointInput[0]);
int pointNumber2 = Convert.ToInt16 (pointInput[1]);
int Latitude = (Convert.ToInt16(items[pointNumber*3]));
int Longtitude = (Convert.ToInt16(items[(pointNumber*3)+1]));
int Elevation = (Convert.ToInt16(items[(pointNumber*3)+2]));
int Latitude2 = (Convert.ToInt16(items[pointNumber2 * 3]));
int Longtitude2 = (Convert.ToInt16(items[(pointNumber2 * 3) + 1]));
int Elevation2 = (Convert.ToInt16(items[(pointNumber2 * 3) + 2]));
Console.WriteLine("Latitude");
Console.WriteLine("Latitude2");