You have a few options here
The first is to use Object.Equals
:
if(b.Equals(iteratorB)) {
// do stuff
}
Be careful using this option; if B
does not override Object.Equals
then the default comparsion is reference equality when B
is a reference type and value equality when B
is a value type. This might not be the behavior that you are seeking and is why without additional information I would consider one of the next two options.
The second is to add a constraint that B
is IComparable
:
public class WidgetBox<A, B, C> where B : IComparable
so that
if(b.CompareTo(iteratorB) == 0) {
// do stuff
}
A third is to require an IEqualityComparer<B>
be passed to the constructor of WidgetBox
public class WidgetBox<A, B, C> {
IEqualityComparer<B> _comparer;
public WidgetBox(IEqualityComparer<B> comparer) {
_comparer = comparer;
}
// details elided
}
Then:
if(_comparer.Equals(b, iteratorB)) {
// do stuff
}
With this last option you can provide an overload that defaults to EqualityComparer<T>.Default
:
public WidgetBox() : this(EqualityComparer<T>.Default) { }