Created
September 5, 2019 18:18
-
-
Save drguildo/84692248400a49a355de7761c8ddf4f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo : IEquatable<Foo> | |
{ | |
public int Id { get; private set; } | |
public Foo(int id) | |
{ | |
this.Id = id; | |
} | |
public bool Equals(Foo other) | |
{ | |
return this.Id == other.Id; | |
} | |
} | |
var l = new List<Foo> { new Foo(1) }; | |
Console.WriteLine(l.Contains(new Foo(1))); // true | |
var h = new HashSet<Foo> { new Foo(1) }; | |
Console.WriteLine(h.Contains(new Foo(1))); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment