c# how do I count lines in a textfile

前端 未结 7 1490
走了就别回头了
走了就别回头了 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:10

    Assuming the file exists and you can open it, that will work.

    It's not very readable or safe...

提交回复
热议问题