Hi.
I have a small problem where I want to find the next "active" item in a list with linq. Then next "active" item is defined by a startDate and EndDate. Here is an example list.
//-- Create Lists of turns
IList<Turn> turns= new List<Turn>(){
new Turn(){Name = "Turn 1", StartDate = DateTime.Parse("2009-05-01"), EndDate = DateTime.Parse("2009-05-01") }
, new Turn(){Name = "Turn 2", StartDate = DateTime.Parse("2009-06-01"), EndDate = DateTime.Parse("2009-06-01") }
, new Turn(){Name = "Turn 3", StartDate = DateTime.Parse("2009-07-01"), EndDate = DateTime.Parse("2009-07-02") }
, new Turn(){Name = "Turn 4", StartDate = DateTime.Parse("2009-08-01"), EndDate = DateTime.Parse("2009-08-03") }
}
//-- Get the next Turn by DateTime.
DateTime toDay = DateTime.Parse("2009-06-02");
//-- Should return the "Turn 3" item...
Turn turn = (from item in turns
where .....
select turn).FirstOrDefault<Turn>();
Is there a good solution to find the next turn by using startDate/endDate properties on Turn. I have tryed to first order the list by startdate and the find First one in the list, but I wounder if there is a more "safe" way to get it that dosen't need the list in correct order to find the correct Turn.