Folks,
Given a set of sorted values (perhaps in a List<T>, SortedList<T,K>, etc.) what’s the best way to go about evaluating inequalities (greater-than, less-than, greater-than-or-equal-to, less-than-or-equal-to a given value)? Possible with any of the standard .net types? Or easily coded up? Any pointers are greatly appreciated.
EDIT – of course I’m trying to make this as fast as possible. needs to be highly performant
If you mean something like the good-old
lower_bound/upper_boundfunctions on C++map<>, AFAIK there’s nothing built-in in C#.On
List<T>there’s aBinarySearchmethod implemented, but it works on exact matching only.Anyway, you can easily implement it by yourself, peraphs using the code in this question as an example:
Is there a Lower Bound function on a SortedList<K ,V>?