title: How do I return results while inside a loop in C#?
body: <p>Essentially, I have a <code>Do..While</code> loop going through some lines from a text file.  I want to process a line, return a value (worked or didn't), then move to the next line.</p>
  
  <p>I have a function called <code>ProcessTXT</code> that accepts 2 strings.  <code>Source</code> and <code>Destination</code> of new file.</p>
  
  <p>Is there a way to set a <code>ReturnedValue string =</code> to the result and have the backgroundworker check to see if the variable changed?  And if so, add this value to the list box?</p>
  
  <pre><code>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);
  }
  </code></pre>
  
  <p>EDIT:  Current test code using Yield.  My output is "TestingGround.Form1+d__0".  Did i do something wrong?</p>
  
  <pre><code>namespace TestingGround
  {
  public partial class Form1 : Form
  {
      static IEnumerable&lt;string&gt; 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));
  
      }
  }
  </code></pre>