The best advice I can give a new programmer is to get to know your debugger. Doing so will help you more easily identify where your code is going wrong and will help you learn quite a bit about how your application executes. I am constantly learning new things when taking the time to step through someone else's (not to mention my own) code.
When your application throws the exception, hit the "Break" button and take a look at the "Autos" window. If it's not visible, you can show it by selecting Debug->Windows->Autos or hitting Ctrl+Alt+V, then A.
The line the debugger stopped on will be:
pline = double.Parse((string) line);
If you look at the current value of the "line" variable in the Autos window, the problem should be apparent. As I mentioned before, double.Parse will throw an exception if the string passed to it cannot be converted. That includes empty strings.
I hope that solves your problem.
: Okay, please bear with me, I'm still very new at programming in general, let alone c#. Here is my code now. I am getting an error that says the input string was not in a correct format. I dont understand why. I believe my code reads in a text file of numbers into a string arraylist, then I'm not sure what it does from there.
: Thanks so much for any help!
:
: using System;
: using System.IO;
: using System.Collections;
: namespace Program2
: {
: class Class1
: {
: static public void Main(string[] args)
: {
: StreamWriter swa=new StreamWriter("c:\\afinal.txt");
: StreamReader sra=new StreamReader("c:\\AColumn.txt");
: string aLine="";
:
: ArrayList aColumn = new ArrayList ();
: while (aLine != null)
: {
: aLine=sra.ReadLine();
: if (aLine != null)
: aColumn.Add(aLine);
:
: Console.WriteLine(aLine);
:
: }
:
: Console.ReadLine();
: sra.Close();
: double pline;
: double[] AField = new double[aColumn.Count];
: for ( int i = 0; i < AField.Length; i++ )
: {
: foreach (string line in aColumn)
: pline = double.Parse((string) line);
: Console.WriteLine (AField [i]);
: }
:
:
: Console.ReadLine();
: swa.Flush();
: swa.Close();
: }
: }
: }
: