I am trying to read a csv file in to an data structure but I can't seem to convert it in to an double type.
static void Main(string[] args)
{
var reader = new StreamReader(File.OpenRead(@"E:\file.csv"));
List<Double> close = new List<Double>();
int counter = 0;
while (!reader.EndOfStream)
{
counter = counter + 1;
var line = reader.ReadLine();
var values = line.Split(',');
string str = values[4];
Double val = Convert.ToDouble(str); //THIS IS THE PROBLEM
Console.WriteLine(values[4].GetType());
}
// Prompt to Exit
Console.WriteLine("Press any key to exit.");
Console.Read();
}
I get an error:
An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll
Additional information: Input string was not in a correct format.
values[4]
is of type System.string