title: What consumes less resources and is faster File.AppendText or File.WriteAllText storing first in StringBuilder?
body: <p>I have to write thousands of dynamically generated lines to a text file.
  I have two choices, Which consumes less resources and is faster than the other?</p>
  
  <p><strong>A. Using StringBuilder and File.WriteAllText</strong></p>
  
  <pre><code>StringBuilder sb = new StringBuilder();
  
  foreach(Data dataItem in Datas)
  {
      sb.AppendLine(
          String.Format(
              "{0}, {1}-{2}",
              dataItem.Property1,
              dataItem.Property2,
              dataItem.Property3));
  }
  
  File.WriteAllText("C:\\example.txt", sb.ToString(), new UTF8Encoding(false)); 
  </code></pre>
  
  <p><strong>B. Using File.AppendText</strong></p>
  
  <pre><code>using(StreamWriter sw = File.AppendText("C:\\example.txt"))
  {
      foreach (Data dataItem in Datas)
      {
          sw.WriteLine(
              String.Format(
                  "{0}, {1}-{2}",
                  dataItem.Property1,
                  dataItem.Property2,
                  dataItem.Property3));
      }
  }
  </code></pre>