If you do it at application level, you'll need to implement IComparable<T>
to tell .NET how to sort your List. Sort()
function of List<T>
uses this interface to decide how list members compare to each other. For simple built-in types, this interface is already implemented in the framework. For your own classes, you need to do it yourself.
Instead of using Sort(), you can use LINQ's OrderBy()
too, using a lambda function. You can then apply BinarySearch()
on the resulting list. Something like this:
var OrigList = context.GetData().ToList(); //or whatever Model function you have
var SortedList = OrigList.OrderBy(i => i.Variation);
var Result = SortList.BinarySearch(/*your condition*/);
Doing it at SQL level is always an option. But you should consider whether you always need the input to be in sorted form. If not, this might create an overhead if this function needs to be called many times.
Edit
Right. You want to know if .NET handles string
comparison in exactly the same way as SQL Server handles varchar
. This has already been discussed in this SO post.