title: If no text to write via StreamWriter, then discard (do not create) the file
body: <p>I am using the StreamWriter to create a file and to write some text to that file. In some cases I have no text to write via StreamWriter, but the file was already created when StreamWriter was initialized.</p>
  
  <pre><code>using (StreamWriter sw = new StreamWriter(@"C:\FileCreated.txt"))
  {
  
  }
  </code></pre>
  
  <p>Currently I am using the following code, when StreamWriter is closed, to check if the FileCreated.txt content is empty, if it is delete it. I am wondering if there is a more elegant approach than this (an option within StreamWriter perhaps)?</p>
  
  <pre><code>if (File.Exists(@"C:\FileCreated.txt"))
  {
     if (new FileInfo(@"C:\FileCreated.txt").Length == 0)
     {
        File.Delete(@"C:\FileCreated.txt");
     }
  }
  </code></pre>
  
  <p>By the way, I must open a stream to write before I can check if there is any text because of some other logic in the code.</p>