第1个回答 2007-12-14
class Program
{
static void Main(string[] args)
{
Program p = new Program();
int j = 0;
Console.WriteLine("第2行的文本是:" + p.FileRowText(2,ref j));
Console.WriteLine("共有" + j + "行");
}
private string FileRowText(int i,ref int j)
{
string path = @"d:\test.txt";
StreamReader sr = File.OpenText(path);
string str = "";
string text = "";
int num = 0;
while ((str=sr.ReadLine()) != null)
{
num++;
if (num == i)
{
text = str;
}
}
j = num;
return text;
}
}本回答被提问者采纳