Fastest way to compare Objects of type DateTime

Posted by radbyx on Stack Overflow See other posts from Stack Overflow or by radbyx
Published on 2010-05-28T00:08:16Z Indexed on 2010/05/28 0:11 UTC
Read the original article Hit count: 178

Filed under:
|

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
                }

© Stack Overflow or respective owner

Related posts about c#

Related posts about optimization