I am setting up a list of date times:
DateTime a1
DateTime a2
DateTime a3
DateTime a4
The above looks like this (as DateTime objects):
3/1/2012 10:56
3/1/2012 17:03
3/1/2012 1:38
3/1/2012 5:33
Then I put them in a list and sort:
List<DateTime> ldtBites = new List<DateTime>();
ldtBites.Add(a1);
ldtBites.Add(a2);
ldtBites.Add(a3);
ldtBites.Add(a4);
ldtBites.Sort();
After Sorting I get this:
3/1/2012 1:38:00 AM
3/1/2012 10:56 AM
3/1/2012 5:03:00 PM
3/1/2012 5:33:00 AM
You omitted the definition of w,x,y,z. I defined them as such:
This causes them to match your values for a1-a4; however, when I run the rest of your code, they sort correctly (a3, a4, a1, a2).
However, I noticed that x and z were the same hour/minute, so my initial test had this:
When I ran this, I got them to come out in the order you were showing (a3, a1, a2, a4); however, after the
AddHours()call went through, thezvalue was actually 3/2/2012, which is why it was last.