Im trying to compare 2 Lists of the type Results, and it constantly just returns the entire list of results, it doesnt seem to filter anything out.

This is the code :

```
  List<Results> Veranderingen = resultaten2.Except(resultaten).ToList();

        foreach(Results x in Veranderingen)
        {
            MessageBox.Show("Nieuwe Data gevonden: " + x.titel + "Van de website" + x.url + "");
        }

```

The code where the lists gets filled is this ( Less important ) :

```
 private void Lijst2invullen()
    {

        OleDbConnection connection = new OleDbConnection();
        connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\martijn\Dropbox\Proftaak Periode 2 Identity\Database11.accdb;
        Persist Security Info=False;";
        connection.Open();

        OleDbCommand cmd2 = new OleDbCommand();
        cmd2.Connection = connection;
        cmd2.CommandText = "SELECT ZoekcriteriaID from Zoekcriteria WHERE ZoekCriteria = '" + Convert.ToString(cbzoektermselecteren.Text) + "';";
        OleDbDataReader reader2 = cmd2.ExecuteReader();

        if (reader2.Read())
        {
            refreshid2 = Convert.ToInt32(reader2["ZoekcriteriaID"]);
        }

        OleDbCommand command5 = new OleDbCommand();
        command5.Connection = connection;
        command5.CommandText = "SELECT Titel, Webadress from Resultaat WHERE ZoekcriteriaID = " + refreshid2 + ";";
        OleDbDataReader reader3 = command5.ExecuteReader();

        while (reader3.Read())
        {
            Results result = new Results();
            result.url = Convert.ToString(reader3["Webadress"]);
            result.titel = Convert.ToString(reader3["Titel"]);

            resultaten2.Add(result);
        }
        reader3.Close();
        label1.Text = "Ziet er goed uit!";
    }

    private void Lijst1invullen()
    {
        OleDbConnection connection = new OleDbConnection();
        connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\martijn\Dropbox\Proftaak Periode 2 Identity\Database11.accdb;
        Persist Security Info=False;";
        connection.Open();

        OleDbCommand cmd1 = new OleDbCommand();
        cmd1.Connection = connection;
        cmd1.CommandText = "SELECT ZoekcriteriaID from Zoekcriteria WHERE ZoekCriteria = '" + Convert.ToString(cbzoektermselecteren.Text) + "';";
        OleDbDataReader reader1 = cmd1.ExecuteReader();

        if (reader1.Read())
        {
            refreshid = Convert.ToInt32(reader1["ZoekcriteriaID"]);
        }

        OleDbCommand command = new OleDbCommand();
        command.Connection = connection;
        command.CommandText = "SELECT Titel, Webadress from Resultaat WHERE ZoekcriteriaID = " + refreshid + ";";
        OleDbDataReader reader = command.ExecuteReader();

        while (reader.Read())
        {
            Results result = new Results();
            result.url = Convert.ToString(reader["Webadress"]);
            result.titel = Convert.ToString(reader["Titel"]);

            resultaten.Add(result);
        }
        reader.Close();
        reader1.Close();

        OleDbCommand command2 = new OleDbCommand();
        command2.Connection = connection;
        command2.CommandText = "DELETE * FROM Resultaat WHERE ZoekcriteriaID = " + refreshid + ";";
        command2.ExecuteNonQuery();

        OleDbCommand command3 = new OleDbCommand();
        command3.Connection = connection;
        command3.CommandText = "DELETE * FROM Zoekcriteria WHERE ZoekCriteriaID = " + refreshid + ";";
        command3.ExecuteNonQuery();

        search.zoekterm = cbzoektermselecteren.Text;
        search.InsertZoekcriteria();
        search.searchding();

    }

```

I think I'm doing something wrong in the syntax of the Except method could anyone help me out?
['https://Stackoverflow.com/questions/34833269', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/5789654/']
There are two ways to compare (for equality) two `Results` objects (and all reference type objects in general):

* The first way is to compare the values of the properties of the two `Results` objects.
* The second way is to compare the references themselves. And by that I mean that two `Results` objects are equal if they are actually a single object but you have two references to it. For example, you can create a single `Results` object and put it in two lists.

The objects in the two lists are clearly different objects, so I am guessing that you want to use the first way of comparison. 

By default, equality check of reference type objects in C# is of the second type. However, you can override this behavior if you want.

One way of overriding this behavior is to override the `Equals` and `GetHashCode` methods in the class. Here is an example:

```
public class Results
{
    public string url { get; set; }
    public string title { get; set; }

    public override bool Equals(object obj)
    {
        Results other = obj as Results;

        if (other == null)
            return false;

        return other.url == this.url && other.title == this.title;
    }

    public override int GetHashCode()
    {
        return new {url, title}.GetHashCode();
    }
}

```

This way, we are telling the system how it should test equality for objects of this type.
I'm sure Yacoub's answer would work and is probably the preferred solution in most cases, but in case you can't modify the Results class, here is another way to do it. Define an implementation of IEqualityComparer for Results, and then pass it as the second argument of the Except method.
EDIT:

```
class Results {
    public string FirstName { get; set; }
    public string LastName { get; set; }
}

class ResultsEqualityComparer : IEqualityComparer<Results> {

    public bool Equals(Results res1, Results res2) {
        return (res1.FirstName == res2.FirstName && res1.LastName == res2.LastName);
    }

    public int GetHashCode(Results res) {
        return new { res.FirstName, res.LastName }.GetHashCode();
    }

}

```

// and here's the example of code passing the ResultsComparer to Except:

```
        var resultaten = new List<Results>() {
        new Results() {FirstName="Bob", LastName="Smith"},
        new Results() {FirstName="Ted", LastName="Wilson"},
        new Results() {FirstName="Alice", LastName="Wilson"},
        new Results() {FirstName="Carol", LastName="Smith"}
        };

        var resultaten2 = new List<Results>() {
        new Results() {FirstName="William", LastName="Smith"},
        new Results() {FirstName="Ted", LastName="Wilson"},
        new Results() {FirstName="Gerhardt", LastName="Wilson"},
        new Results() {FirstName="Carol", LastName="Smith"}
        };

        var comparer = new ResultsEqualityComparer();

        List<Results> Veranderingen = resultaten2.Except(resultaten, comparer).ToList();

        foreach (var x in Veranderingen) {
            Console.WriteLine(x.FirstName + " " + x.LastName);
        }

```

// prints out:
William Smith
Gerhardt Wilson