为什么我的文件只读取最后一行?

时间:2017-11-20 12:46:53

标签: c#

我想创建一个表单,我可以为员工生成工资单。 payslip本身基于我放在文本文件上的级别 这是我的代码

string line;
string a;
string b;
string[] row = new string[6];
System.IO.StreamReader file = new System.IO.StreamReader(@string.filename);

bool pay = false;

while ((line = file.ReadLine()) != null)
{
    row = line.Split(',');
    a = row[1];  /* This is my employee' name*/
    if (a == label8.Text)
    {
        b = row[5];
        pay = true;
    }
}

if (pay)
{
    b = row[5]; /* This is my employee's level*/
    int level = Convert.ToInt32(b);
    int basicsalary = level * 1000;
    label9.Text = basicsalary.ToString();
} 

file.Close();

我正在使用这种代码但不知何故它在这种形式下效果不佳,因为它只读取最后一行。

0 个答案:

没有答案
相关问题