How best to read a File into List

后端 未结 10 1275
盖世英雄少女心
盖世英雄少女心 2020-11-27 17:34

I am using a list to limit the file size since the target is limited in disk and ram. This is what I am doing now but is there a more efficient way?

readonly         


        
10条回答
  •  庸人自扰
    2020-11-27 18:04

    List lines = new List();
     using (var sr = new StreamReader("file.txt"))
     {
          while (sr.Peek() >= 0)
              lines.Add(sr.ReadLine());
     }
    

    i would suggest this... of Groo's answer.

提交回复
热议问题