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();
精彩评论