How to determine the earliest/latest DateTime in a collection?

Viewed 14273

Question 1: In a collection of DateTime objects, how to determine which one is the earliest/latest?

Question 2: In a collection of objects, how to determine which object has the earliest/latest DateTime property?

For example:

class VideoGame
{
    DateTime ReleaseDate { get; set; }
}

Which VideoGame will be released first/last?

var allGames = new List<VideoGame>();
allGames.Add( new VideoGame() { ReleaseDate = new DateTime(2010, 10, 4)} );
allGames.Add( new VideoGame() { ReleaseDate = new DateTime(2012, 7, 14)} );
allGames.Add( new VideoGame() { ReleaseDate = new DateTime(2014, 5, 26)} );
5 Answers
Related