c# how do I count lines in a textfile

前端 未结 7 1291
走了就别回头了
走了就别回头了 2021-02-04 13:39

any problems with doing this?

int  i = new StreamReader(\"file.txt\").ReadToEnd().Split(new char[] {\'\\n\'}).Length
7条回答
  •  梦如初夏
    2021-02-04 14:09

    That should do the trick:

    using System.Linq;
    
    ....
    
    int i = File.ReadLines(file).Count();
    

提交回复
热议问题