Bug in the File.ReadLines(..) method of the .net framework 4.0

后端 未结 7 1365
渐次进展
渐次进展 2021-01-11 16:31

This code :

IEnumerable lines = File.ReadLines(\"file path\");
foreach (var line in lines)
{
    Console.WriteLine(line); 
}
foreach (var line          


        
7条回答
  •  有刺的猬
    2021-01-11 16:33

    If you need to access the lines twice you can always buffer them into a List

    using System.Linq;
    
    List lines = File.ReadLines("file path").ToList(); 
    foreach (var line in lines) 
    { 
        Console.WriteLine(line);  
    } 
    foreach (var line in lines) 
    {  
        Console.WriteLine(line);  
    } 
    

提交回复
热议问题