I have created the following LINQ query to demonstrate the problem:
string[] dateStrings = new string[] { "2009-07-20 13:00:00", "2009-07-20 16:00:00", "2009-07-20 09:00:00" };
DateTime dateValue = DateTime.MinValue;
var results =
from dateString in dateStrings
where DateTime.TryParse(dateString, out dateValue)
orderby dateValue descending
select dateValue;
You'd expect the result to be a list of DateTimes in the reversed order:
20-7-2009 16:00:00
20-7-2009 13:00:00
20-7-2009 9:00:00
However all I get is this:
20-7-2009 9:00:00
20-7-2009 9:00:00
20-7-2009 9:00:00
What am I doing wrong? If you remove the orderby statement you'll notice a normal list of DateTime's.