Skip to content

Instantly share code, notes, and snippets.

@drguildo
Created September 5, 2019 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drguildo/84692248400a49a355de7761c8ddf4f7 to your computer and use it in GitHub Desktop.
Save drguildo/84692248400a49a355de7761c8ddf4f7 to your computer and use it in GitHub Desktop.
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