I have a variable List< Tuple< DateTime, double>> myList.
Given a datetime, hope it returns the Tuple that precedes
the datetime by using Linq.
For example, if "2013-Feb-08 21:34:00" is supplied, want to
see the last Tuple in the list whose datetime is before this timestamp.
How do I do this with Linq?
Edit:
myList.Where(t => t.Item1 < timestamp).Last();
solved my issue.
Which is better in terms of performance compared to
myList.TakeWhile(t => t.Item1 < timestamp).Last();
With MoreLinq MaxBy (available from NuGet):
Or (if items are sorted):
UPDATE (with binary search) write comparer:
Then search