且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取每行文件中的数字总和

更新时间:2023-02-10 21:46:20

您正在 while 条件中执行 readline,并在 while 范围的主体中再次执行,因此跳过了 1 个 readline 指令(在 while 条件中).试试这个:

you're doing a readline in your while condition and again in the body of your while scope, thus skipping 1 readline instruction (in the while condition). try this instead:

StreamReader ar = new StreamReader(@"C:\Users\arash\Desktop\problem1 (3).in");
string s = ar.ReadLine();
while (s != null)
{
    //string[] spl = s.Split(' ');
    // below code seems safer, blatantly copied from one of the other answers..
    string[] spl = s.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries);
    MessageBox.Show(spl[0]);
    s = ar.ReadLine();
 }