title: Compare Items in two Lists and return non matching Items
body: <p>So I have two Lists. </p>
  
  <pre><code>List&lt;Farmer&gt; CSVFarmer;
  List&lt;Farmer&gt; Farmers;
  </code></pre>
  
  <p>CSVFarmer List gets its items from a method that will read a csv file.</p>
  
  <p>Farmers List gets its items from a table in a sql database;</p>
  
  <p>Now what I want to do is compare the two lists and return a list of non matching items;</p>
  
  <p>For example if List CSVFarmer has:</p>
  
  <pre><code>FarmerName     ContractNumber   ContactNumber
  John           2468             12345
  Mike           13579            15790
  </code></pre>
  
  <p>And List Farmers has:</p>
  
  <pre><code>FarmerName     ContractNumber   ContactNumber
  Mike           13579            15790
  </code></pre>
  
  <p>The list being returned should only have one item in it : Farmer John.
  Farmer Class:</p>
  
  <pre><code> public class Farmer:INotifyPropertyChanged
  {
      int _id;
      string _firstName;
      string _farmerNo;
      string _contactNumber;
  
      public Farmer()
      {
          _firstName = string.Empty;
          _farmerNo = string.Empty;
          _contactNumber = string.Empty;
      }
  
      public int Id
      {
          get { return _id; }
          set
          {
              _id = value;
              OnPropertyChanged("Id");
          }
      }
      public string FirstName
      {
          get { return _firstName; }
          set
          {
              _firstName = value;
              OnPropertyChanged("FirstName");
          }
      }
      public string FarmerNo
      {
          get { return _farmerNo; }
          set
          {
              _farmerNo = value;
              OnPropertyChanged("FarmerNo");
          }
      }
      public string ContactNumber
      {
          get { return _contactNumber; }
          set
          {
              _contactNumber = value;
              OnPropertyChanged("ContactNumber");
          }
      }
  
  
      public event PropertyChangedEventHandler PropertyChanged;
      private void OnPropertyChanged (string property)
      {
          if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(property));
      }
  
  }
  </code></pre>
  
  <p>Ive tried this:</p>
  
  <pre><code>public class vmUserManagement
  {
  public List&lt;Farmer&gt; Farmer { get; set; }
  public List&lt;Farmer&gt; CSVFarmers { get; set; }
  public List&lt;Farmer&gt; Farmers { get; set; }
  
  
  public vmUserManagement()
      {
          CSVFarmers = new List&lt;Farmer&gt;();
          Farmers = new List&lt;Farmer&gt;();
          Farmer = new List&lt;Farmer&gt;();
     }
  
  public List&lt;Farmer&gt; getAllFarmers()
      {
          Farmers = RepoDapper.getAllFarmers();
          return Farmers;
      }
  
  public List&lt;Farmer&gt; CSVImportFarmer()
      {
          OpenFileDialog openFile = new OpenFileDialog();
          openFile.DefaultExt = ".csv";
          openFile.Filter = "(.csv) | *.csv";
  
          var browseFile = openFile.ShowDialog();
          if (browseFile == true)
          {
              string FilePath = openFile.FileName;
              List&lt;Farmer&gt; values = File.ReadAllLines(FilePath).Select(v =&gt; FromFarmerCsv(v)).ToList();
              CSVFarmers = values;
          }
          return CSVFarmers;
      }
  
   public static Farmer FromFarmerCsv(string csvLine)
      {
          string[] values = csvLine.Split(',');
          Farmer farmer = new Farmer();
          farmer.FirstName = values[0];
          farmer.FarmerNo = values[1];
          farmer.ContactNumber = values[2];
          return farmer;
      }
  
  
  public List&lt;Farmer&gt; validateFarmerList()
      {
  
  
          foreach (var a in CSVFarmers)
          {
              foreach (var b in Farmers)
              {
  
                      if (a != b)
                      {
                          Farmer.Add(a);
                      }
  
              }
          }
  
          return Farmer;
      }
  }
  </code></pre>
  
  <p>The problem I'm having is that  I will end up with two entries in List Farmer. Both for Farmer John and Farmer Mike. When I should only be getting a List containing Farmer John. Why is that?</p>
  
  <p>I've also tried using Except:</p>
  
  <pre><code> public List&lt;Farmer&gt; validateFarmerList()
      {           
  
          Farmer = CSVFarmers.Except(Farmers).ToList();
          return Farmer;
      }
  </code></pre>
  
  <p>But I still get two items in my Farmer List (Farmer John and Mike) instead of one.
  Am I missing something? Any help will be much appreciated.</p>