开发者

Get Earliest date from from IEnumerable<DateTime>

I have an IEnumerable<DateTime> with a number of dates in i开发者_开发问答t. How would I get the earliest date from that collection?

Thanks!

Dave


You can do this immediately with LINQ using Enumerable.Min.

DateTime minDate = dateCollection.Min();

Since DateTime implements IComparable<DateTime>, Enumerable.Min will use DateTime.CompareTo to find the minimum DateTime in the collection.


var earliest = collection.Min();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜