I have a
var itemList = new List<Item>()
and a
var searchSet = new HashSet<TestItem>(new TestItemComparer());
For each element in the itemList I look for its existance in the searchSet via the Number property.
I search like this: ( The item.Numer is an enumerated element of the itemList)
var isFound = searchSet.Contains(new TestItem{ Number = item.Numer });
public class TestItemComparer: IEqualityComparer<TestItem>
{
public bool Equals(TestItem x, TestItem y)
{
return x.Number == y.Number;
}
public int GetHashCode(TestItem obj)
{
return obj.Number.GetHashCode();
}
}
The reason why my searchSet has a comlex type TestItem
and not integer
is because I still want to combine my search with some other properties on the TestItem class.
How can I still use this amazing fast HashSet.Contains
method but combine the Number search with other properties?
Should I change my TestItemComparer
for this?