日期:2014-05-19  浏览次数:20890 次

C#中如何得到指定行到文件尾的每行内容?
如题!

------解决方案--------------------
是什么文件啊?能否举个例子
------解决方案--------------------
StreamReader sr = new StreamReader( "D:\\a.txt ");
string str;
string result = " ";
int count= 0;
int index = 3;//指定行
while ((str = sr.ReadLine()) != null)
{
if (count> = (index-1))
{
result += str;
}
count++;
}
MessageBox.Show(result.ToString());
------解决方案--------------------
public string getindexstr(int index)
{
string[] all = File.ReadAllLines( "D:\\a.txt ");
return all[index];
}
------解决方案--------------------
理解错了
public string getindexstr(int index)
{
string temp;

string[] all = File.ReadAllLines( "D:\\a.txt ");

for (int i = index; i < all.Length; i++)
{
temp += all[i];
}
return temp;
}