I made this. Is this the fastest way to find lastest DateTime of my collection of DateTimes?
I'm wondering if there is a method for what i'm doing inside the foreach, but even if there is, I can't see how it can be faster than what i all ready got.
List<StateLog> stateLogs = db.StateLog.Where(p => p.ProductID == product.ProductID).ToList();
DateTime lastTimeStamp = DateTime.MinValue;
foreach (var stateLog in stateLogs)
{
int result = DateTime.Compare(lastTimeStamp, stateLog.TimeStamp);
if (result < 0)
lastTimeStamp = stateLog.TimeStamp; // sæt fordi timestamp er senere
}