c# how do I count lines in a textfile

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

    Mayby this?

    string file = new StreamReader("YourFile.txt").ReadToEnd();
    string[] lines = file.Split('\n');
    int countOfLines = lines.GetLength(0));
    

提交回复
热议问题