You should not have for
inside while
. You only need one loop:
var i = 0;
while((line = file.ReadLine()) != null)
{
fltArray[i] = Convert.ToSingle(line);
if (i == 999999)
Console.WriteLine("At 999999");
i++;
}
or with for
:
for(i=0; i < 1000000 && (line = file.ReadLine()) != null; i++)
{
fltArray[i] = Convert.ToSingle(line);
if (i == 999999)
Console.WriteLine("At 999999");
}
Update
I'm getting following results for your file:
Creating Single array...
Array created, making string...
String created, opening file...
File opened, creating stopwatch and starting main execution event. See you on the other side.
At 999999
It took 00:00:00.42 to read a thousand lines into the array.
Element 0 is: 0,9976465
Element 999999 is: 0,04730097
Release build, run outside of VS, i5-3317U @ 1.7GHz.