数组和文本文件

Jon*_*Jon 2 c# arrays text-files

我想带一个包含很多行的文本文件并将其转换为数组.例如,如果文本文件是:

第1行

第2行

第3行

4号线

它会导致

string[] stringList = { "Line 1", "Line 2", "Line 3", "Line 4" };
Run Code Online (Sandbox Code Playgroud)

我该怎么做呢?

我试过这个:

string line;
string[] accountList;
            using (StreamReader file = new StreamReader(accountFileLocation.Text))
            {
                while (line = file.ReadLine() != null)
                {
                    stringList += line;
                }
            }
Run Code Online (Sandbox Code Playgroud)

然而,错误:

无法将类型'bool'隐式转换为'string'

无法将'string'类型转换为'string []'

无法将类型'string'隐式转换为'string []'

BRA*_*mel 7

只是用

  string[] lines =  File.ReadAllLines(yourpathFile);  
Run Code Online (Sandbox Code Playgroud)