开发者

Get Earliest date from from IEnumerable<DateTime>

开发者 https://www.devze.com 2023-02-15 21:11 出处:网络
I have an IEnumerable<DateTime> with a number of dates in i开发者_开发问答t. How would I get the earliest date from that collection?

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

精彩评论

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