[Solved] C# get pair closest to value [closed]

You want something like this: public static Pair FindClosest(IEnumerable<Pair> list, int value) { Pair closest = null; if (list != null && list.Count() > 0) { foreach (var pair in list) { if (value <= pair.Max) { closest = pair; break; } } if (closest == null) { closest = list.Last(); } } return closest; … Read more