title: extracting lines from a file with C#
body: <p>I have a text file1 and I wish to extract lines (which don't exist in file2)in a new file3  </p>
  
  <p>example :</p>
  
  <p>file1:</p>
  
  <pre><code>/**
  * Gets the total volume.
  *
  * @return the total volume
  */
  public int getTotalVolume() {return totalVolume;}
  </code></pre>
  
  <p>file2:</p>
  
  <pre><code>* Gets the total volume.
  *
  * @return the total volume
  </code></pre>
  
  <p>file3:</p>
  
  <pre><code>/**
   */
  public int getTotalVolume() {return totalVolume;}
  </code></pre>
  
  <p>my function:</p>
  
  <pre><code>    public void Traitv2(string file1, string file2, string file3)
      {
          StreamReader monStreamReaderfile1 = new StreamReader(file1);
          StreamWriter monStreamWriterfile3 = new StreamWriter(file3);
          string ligne = monStreamReaderfile1.ReadLine();
  
          while (ligne != null)
          {
              StreamReader monStreamReaderfile2 = new StreamReader(file2);
              string ligne1 = monStreamReaderfile2.ReadLine();
              while (ligne1 != null)
              {
                  if (!ligne.Equals(ligne1))
                  {
  
                      Console.WriteLine(ligne);
                      monStreamWriterfile3.WriteLine(ligne);
                  }
  
                  ligne1 = monStreamReaderfile2.ReadLine();
                  ligne = monStreamReaderfile1.ReadLine();
              }
  
              ligne = monStreamReaderfile1.ReadLine();
              monStreamReaderfile2.Close();
          }
  
          monStreamWriterfile3.Close();
          monStreamReaderfile1.Close();
      }
  </code></pre>
  
  <p>When I run this function, the result is false and an error occurs: error Object reference not set to an instance of an object</p>