title: Are there better ways to overwrite a file then check for changes (in C#)?
body: <p><strong>Situation:</strong></p>
  
  <p>I have a C# program which does the following:</p>
  
  <ul>
  <li>Generate many files (replacing the ones generated last time the program ran.)</li>
  <li>Read those files and perform a time-consuming computation.</li>
  </ul>
  
  <p><strong>Problem:</strong></p>
  
  <p>I only want to perform the time-consuming computation on files which have actually changed since the last time I ran the program.</p>
  
  <p><strong>Solution 1:</strong></p>
  
  <ul>
  <li>Rename the old file.</li>
  <li>Write the new file.</li>
  <li>Read and compare both files.</li>
  </ul>
  
  <p>This involves writing one file and reading two, which seems like more disk access than necessary.</p>
  
  <p><strong>Solution 2:</strong></p>
  
  <ul>
  <li>Write to a string instead of a file.</li>
  <li>Read the old file and compare to the string.</li>
  <li>If they are different, overwrite the old file.</li>
  </ul>
  
  <p>This would involve reading one file and possibly writing one, which seems like a big improvement over my first idea.</p>
  
  <p><strong>Question:</strong></p>
  
  <p>Can you describe a better way to solve my problem? (and explain why it is better?)</p>