gpt4 book ai didi

c# - readline 然后将指针移回?

转载 作者:太空狗 更新时间:2023-10-29 22:32:35 25 4
gpt4 key购买 nike

streamreader 中是否有一个函数允许查看/阅读下一行以获取更多信息,而无需实际将迭代器移动到下一个位置?

当前行的 Action 取决于下一行,但我想保持使用这个代码块的完整性

while((Line = sr.ReadLine())!=null)

最佳答案

原则上,没有必要做这样的事情。如果你想关联两个连续的行,只需根据这个事实调整分析(在阅读第 2 行的同时执行第 1 行的操作)。示例代码:

using (System.IO.StreamReader sr = new System.IO.StreamReader("path"))
{
string line = null;
string prevLine = null;
while ((line = sr.ReadLine()) != null)
{
if (prevLine != null)
{
//perform all the actions you wish with the previous line now
}

prevLine = line;
}
}

这可能会根据需要进行调整以处理尽可能多的行(以前行的集合而不仅仅是 prevLine)。

关于c# - readline 然后将指针移回?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20360110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com