//设置所读取文件的路径
string txtPath = @"D:\mytxt.txt";
string content = "";
int lineCount = 0; //设置读取流StreamReader与编码方式
using (StreamReader sr = new StreamReader(txtPath, Encoding.UTF8))
{
//若流的读取位置不在结尾处,则继续读取下行
while (!sr.EndOfStream)
{ lineCount++;
}
}
//返回总行数
return lineCount;