用c#读取一个文本文件

Reading a text file with c#

到目前为止这是我的代码。我遇到的问题是找不到文件。

命名空间Assignment_Forms_Aplication { public 部分 class Form1 : 表格 { public 表格 1() { 初始化组件(); }

    private void Form1_Load(object sender, EventArgs e)
    {

        //Define Variable
        string[] words = new string[10];

        // Read the text from the text file, and insert it into the array
        StreamReader SR = new StreamReader(@"Library.txt");
        //
        for (int i = 0; i < 10; i++)
        {
            words[i] = SR.ReadLine();
        }

        // Close the text file, so other applications/processes can use it
        SR.Close();

    }
}

}

嗨盖伦使用以下方法:

File.ReadAllLines(@"location");
  • 如果位置正确,那么这将起作用
  • 赋值给变量,例如