读取文件中文本的问题

来源:百度知道 编辑:UC知道 时间:2024/05/10 14:04:14
我想读取一个文件中的文本,获取该文件中的总行数,定义个数组,将文本中的文字赋值给该改数组。要求数组中的每一个元素的值为文本中一行

提示
取总行数

private int countline(string fullfilename)
{
System.IO.StreamReader sr=new System.IO.StreamReader(fullfilename);
int line=0;
while(sr.ReadLine()!=null)
{
line++;
}
sr.Close();
return line;

}

用StreamReader

详查MSDN

StreamReader !

同意二楼的意思,Readline()就可以了