C#

C# IF ListBox Arrays 2D Arrays Read File Example 1 Example Midterm 1 Example Midterm 2 Example 5 Example 7 Group Project 2 Example 9 Group Project 2
O O

Weather Controls

Time Of Day
Rain
Wind Speed
Wind Direction
Clouds

C# : Read File

2017-01-01

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);
}