static void Main(string[] args) { //----------------------- //-- -- //--Load data from file-- //--Begin -- //-- -- //----------------------- //Load text file string AirportDataFile; AirportDataFile = File.ReadAllText("Airports.txt"); Console.WriteLine(AirportDataFile); NewLine(); //Divide up text file string[] AirportDataLines = AirportDataFile.Split(System.Environment.NewLine); int Lines = AirportDataLines.Length; Console.WriteLine("Number of airports: " + Convert.ToString(Lines)); NewLine(); //Declare array references string[] PortCode, PortName; int[] DistanceFromLPL, DistanceFromBOH; //Create new arrays and connect references PortCode = new string[Lines]; PortName = new string[Lines]; DistanceFromLPL = new int[Lines]; DistanceFromBOH = new int[Lines]; //Put data into arrays for (int i = 0; i < (Lines - 1); i++) { string[] Fields = AirportDataLines[i].Split(","); for (int x = 0; x < 4; x++) { Console.WriteLine(Fields[x]); } PortCode[i] = Fields[0]; PortName[i] = Fields[1]; DistanceFromLPL[i] = Convert.ToInt32(Fields[2]); DistanceFromBOH[i] = Convert.ToInt32(Fields[3]); } //----------------------- //-- -- //--Load data from file-- //--End -- //-- -- //----------------------- }
static void Main(string[] args) { Console.WriteLine("Hello World!"); //Load text file string AirportDataFile; AirportDataFile = File.ReadAllText("Airports.txt"); Console.WriteLine(AirportDataFile); //Divide up text file string[] AirportDataLines = AirportDataFile.Split('\n'); Console.WriteLine(AirportDataLines); int Lines = AirportDataLines.Length; Console.WriteLine(AirportDataLines); Console.WriteLine("Number of airports: " + Convert.ToString(Lines)); //Create arrays and define their length string[] PortCode; string[] PortName; int[] DistanceFromLPL; int[] DistanceFromBOH; PortCode = new string[Lines]; PortName = new string[Lines]; DistanceFromLPL = new int[Lines]; DistanceFromBOH = new int[Lines]; //Input data into arrays for (int i = 0; i < Lines; i++) { string[] Fields = AirportDataLines[i].Split(","); PortCode[i] = Fields[0]; Console.WriteLine(Convert.ToString(PortCode[i])); PortName[i] = Fields[1]; Console.WriteLine(Convert.ToString(PortName[i])); DistanceFromLPL[i] = Convert.ToInt32(Fields[2]); Console.WriteLine(Convert.ToString(DistanceFromLPL[i])); Console.WriteLine(Convert.ToString(Fields[3])); DistanceFromBOH[i] = Convert.ToInt32(Fields[3]); } Menu(); }