我想将文件中的数字加在一起。 数字为31 32 45 65 67 54 43 78 98 33 14 25。 答案应该是585,但是代码给出287。 我在哪里出错以及如何解决?
using System;
using System.IO;
namespace TaaviSimsonTest
{
class Program
{
static void Main(string[] args)
{
using (textreader reader = File.OpenText("C:\\temp\\andmed.txt"))
{
int sum = 0;
while (reader.ReadLine() != null)
{
int i = int.Parse(reader.ReadLine());
sum += i;
}
Console.WriteLine(sum);
}
}
}
}