Problem : you are trying to call ReadLine()
method twice.
your stream becomes null
by end of the while()
loop as you are Reading till the end of file.
while (reader.ReadLine() != null) //<-- reading 1st time
{
lineCount++;
} //stream becomes null here
for(var count = 0; count < lineCount; ++count)
{
var data = reader.ReadLine().Split(','); //<-- reading 2nd time
GlobalDataClass.dDataArray[count, 0] = double.Parse(data[0]);
GlobalDataClass.dDataArray[count, 1] = double.Parse(data[1]);
}
Solution : You can use File.ReadLines() method to read the all lines in a file.
Try This:
string filename = openFileDialog1.FileName;
var lineCount = 0;
using (var reader in File.ReadLines(@filename))
{
var data=reader.Split(',');
lineCount ++;
GlobalDataClass.dDataArray[count, 0] = double.Parse(data[0]);
GlobalDataClass.dDataArray[count, 1] = double.Parse(data[1]);
}
ShowGraphData(lineCount);