I have an object with attributes ; startIndex, endIndex
I am able to do binary search based on startIndex by implementing the following :
int IComparable.CompareTo(object obj)
{
Repeat r = (Repeat)obj;
return this.startIndex.CompareTo(r.startIndex);
}
However with the same Repeat Object I d like to do binary search also on the end index separately.
How can i do this ?
Thanks.
Best Answer
If you're using the
Array.BinarySearch()
orList<T>.BinarySearch()
methods, you can use the overload that takes anIComparer
orIComparer<T>
. Then you can implement the comparison semantics in a separate class and pass it in when you want to do a search.