基本上,我有一个Do..While
循环遍历文本文件中的某些行。我想处理一行,返回一个值(工作或没有),然后移到下一行。
我有一个名为ProcessTXT
的函数,它接受2个字符串。新文件的Source
和Destination
。
有没有办法为结果设置ReturnedValue string =
并让后台工作人员检查变量是否发生了变化?如果是这样,请将此值添加到列表框中吗?
private void TranslatePOD(string strSource, string strDest,)
{
TextWriter tw = new StreamWriter(strDest);
TextReader tr = new StreamReader(strSource);
do
{
//My Code doing stuff
//Need to send a result somehow now, but i have more work to do in this loop
//Then using tw.writeline() to write my results to my new file
} while (tr.ReadLine() != null);
}
编辑:使用Yield的当前测试代码。我的输出是" TestingGround.Form1 + d__0"。我做错了什么?
namespace TestingGround
{
public partial class Form1 : Form
{
static IEnumerable<string> TestYield(string strSource)
{
TextReader tr = new StreamReader(strSource);
string strCurLine = System.String.Empty;
while ((strCurLine = tr.ReadLine()) != null)
{
yield return strCurLine;
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string MySource = System.String.Empty;
MySource = @"C:\PODTest\Export Script\Export\Shipment List.csv";
listBox1.Items.Add(TestYield(MySource));
}
}