Reputation: 2562
I have an IEnumerable<DateTime>
with a number of dates in it. How would I get the earliest date from that collection?
Thanks!
Dave
Upvotes: 11
Views: 7930
Reputation: 241621
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.
Upvotes: 20