loop - while not end of file - push to array
int index = 0;
while (!inputFile.EndOfStream)
{
double salesOut;
if (double.TryParse(inputFile.ReadLine(), out salesOut))
{
salesFiguresArr[index] = salesOut;
}
index++;
}
parse read line
double salesOut;
if (double.TryParse(inputFile.ReadLine(), out salesOut))
{
salesFiguresArr[index] = salesOut;
}
read file, to array
using System.IO;
const int arrCount = 7;
double[] salesFiguresArr = new double[arrCount];
try
{
StreamReader inputFile;
inputFile = File.OpenText("Sales.txt");
int index = 0;
while (!inputFile.EndOfStream)
{
double salesOut;
if (double.TryParse(inputFile.ReadLine(), out salesOut))
{
salesFiguresArr[index] = salesOut;
}
index++;
}
inputFile.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}