That question probably sounded extremely confusing, but it’s difficult to describe what I want to do. Basically, I have a list of DateTime objects and I want to make a new list that contains the objects from the list that represent the latest time for each date represented in the list. For example, say I have a list containing these DateTimes:
- 12/13/2012 2:00:00 AM
- 12/13/2012 4:00:00 AM
- 12/13/2012 8:00:00 PM
- 12/14/2012 5:00:00 PM
- 12/14/2012 3:00:00 AM
- 12/15/2012 10:00:00 AM
I want my results list to contain the following:
- 12/13/2012 8:00:00 PM
- 12/14/2012 5:00:00 PM
- 12/15/2012 10:00:00 AM
I know I can do this using LINQ. I’m just having a hard time trying to wrap my mind around what is happening. I think I have to select from an IEnumerable<IEnumerable<DateTime>> where the inner IEnumerable is a list of DateTimes that all have the same date, and then I want to order those by descending and select the first one.
I am quite lost…
Try this: