title: Nested using statements in C#
body: <p>I am working on a project. I have to compare the contents of two files and see if they match each other precisely.</p>
  
  <p>Before a lot of error-checking and validation, my first draft is:</p>
  
  <pre><code>  DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory + "\\TestArea\\");
    FileInfo[] files = di.GetFiles(filename + ".*");
  
    FileInfo outputFile = files.Where(f =&gt; f.Extension == ".out").Single&lt;FileInfo&gt;();
    FileInfo expectedFile = files.Where(f =&gt; f.Extension == ".exp").Single &lt;FileInfo&gt;();
  
    using (StreamReader outFile = new StreamReader(outputFile.OpenRead()))
    {
      using (StreamReader expFile = new StreamReader(expectedFile.OpenRead()))
      {
        while (!(outFile.EndOfStream || expFile.EndOfStream))
        {
          if (outFile.ReadLine() != expFile.ReadLine())
          {
            return false;
          }
        }
        return (outFile.EndOfStream &amp;&amp; expFile.EndOfStream);
      }
    }
  </code></pre>
  
  <p>It seems a little odd to have nested <code>using</code> statements.</p>
  
  <p>Is there a better way to do this?</p>