I would like to know how I can add all the lines in a file (decimals) into a total sum variable.
This is what I have:
decimal numData, numTotal;
StreamReader file1;
file1 = File.OpenText("data1.dat");
numData = file1.ReadLine();
if(decimal.TryParse(file1.ReadLine().Trim(), out sumData))
{
numTotal = numData;
listBoxNums.Items.Add(numTotal.ToString("c2"));
}
but it only gives me the first line of the file, is there a way to sum all the lines in the file?