I would like to use HashSet<>
in order to store large quantities (50-100) of a certain custom class, lets call it "Poster." As far as I know there is some performance benefit in using HashSet<>
for large number of items over List<>
. But in order to take advantage of this performance gain, do I "need" to define both of these?
public bool Equals(Poster a, Poster b)
public int GetHashCode(Poster obj)
UPDATE: For anyone looking on how to implement these, this is how I've done it:
public bool Equals(PosterImage a, PosterImage b)
{
return (a.ApiId == b.ApiId);
}
public int GetHashCode(PosterImage obj)
{
return ((PosterImage) obj).ApiId.GetHashCode();
}