title: Is using StringBuilder Remove method more memory efficient than creating a new StringBuilder in loop?
body: <p>In C# which is more memory efficient: Option #1 or Option #2?</p>
  
  <pre><code>public void TestStringBuilder()
  {
      //potentially a collection with several hundred items:
      string[] outputStrings = new string[] { "test1", "test2", "test3" };
  
      //Option #1
      StringBuilder formattedOutput = new StringBuilder();
      foreach (string outputString in outputStrings)
      {
          formattedOutput.Append("prefix ");
          formattedOutput.Append(outputString);
          formattedOutput.Append(" postfix");
  
          string output = formattedOutput.ToString();
          ExistingOutputMethodThatOnlyTakesAString(output);
  
          //Clear existing string to make ready for next iteration:
          formattedOutput.Remove(0, output.Length);
      }
  
      //Option #2
      foreach (string outputString in outputStrings)
      {
          StringBuilder formattedOutputInsideALoop = new StringBuilder();
  
          formattedOutputInsideALoop.Append("prefix ");
          formattedOutputInsideALoop.Append(outputString);
          formattedOutputInsideALoop.Append(" postfix");
  
          ExistingOutputMethodThatOnlyTakesAString(
             formattedOutputInsideALoop.ToString());
      }
  }
  
  private void ExistingOutputMethodThatOnlyTakesAString(string output)
  {
      //This method actually writes out to a file.
      System.Console.WriteLine(output);
  }
  </code></pre>