Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting runtime error, C# Converting Array to Int
    primarykey
    data
    text
    <p>for some reason this will compile but it comes out with an error at the end and I can't figure out why. The first part of the code is to display a table from a text file which works correctly, the second part doesn't.</p> <p>I don't think it even gets to the Console.WriteLine bit, which was a way of checking whether it did. Can anyone see why? </p> <p>Thanks for any help you can give!</p> <pre><code>class Program { static void Main(string[] args) { List&lt;float&gt; inputList = new List&lt;float&gt;(); 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 &lt; 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"); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload