Using lambda expressions:
void Summarise(Record[] arr)
{
if (!(arr == null || arr.Length == 0))
{
List<Record> recordList = new List<Record>(arr);
recordList.Sort((x,y) => { return x.Date.CompareTo(y.Date); });
// I may have this the wrong way round, but you get the idea.
DateTime earliest = recordList[0];
DateTime latest = recordList[recordList.Count];
}
}
Essentially:
- Sort into a new list in order of date
- Select the first and last elements of that list
UPDATE: Thinking about it, I'm not sure that this is the way to do it if you care at all about performance, as sorting the entire list will result in many more comparisons than just scanning for the highest / lowest values.