I have a set of objects, each of which has an int Frame property. Given int, I want to find the object in the collection with the closest frame.
Here is what I am doing so far:
public static void Search(int frameNumber) { var differences = (from rec in _records select new { FrameDiff = Math.Abs(rec.Frame - frameNumber), Record = rec }).OrderBy(x => x.FrameDiff); var closestRecord = differences.FirstOrDefault().Record;
This is great and everything except 200,000 items in my collection, and I call this method very often. Is there a relatively simple and effective way to do this?
source share