似乎您只想对日期/时间对象进行排序。由于您发布的代码不是 C#,我会做一些假设。
首先:假设您在DateTime
object中有日期/时间组合。我假设你有他们的清单。
List<DateTime> dateTimes = new List<DateTime>();
dateTimes.AddRange(new []
{
new DateTime(2012, 02, 15, 12, 30, 00), // 15/02/12 12.30PM
new DateTime(2012, 02, 15, 13, 30, 00), // 15/02/12 01.30PM
new DateTime(2012, 02, 15, 11, 00, 00), // 15/02/12 11.00AM
new DateTime(2012, 02, 15, 12, 00, 00), // 15/02/12 12.00PM
new DateTime(2012, 02, 15, 12, 00, 00), // 15/02/12 12.00PM
new DateTime(2012, 02, 15, 01, 00, 00), // 15/02/12 01.00PM
});
您可以像这样对它们进行就地排序:
dateTimes.Sort();
或者,如果您有一个数组或任何IEnumerable<T>
一般的数组,您可以获得一个新的有序可枚举序列:
IEnumerable<DateTime> dateTimes = new []
{
new DateTime(2012, 02, 15, 12, 30, 00), // 15/02/12 12.30PM
new DateTime(2012, 02, 15, 13, 30, 00), // 15/02/12 01.30PM
new DateTime(2012, 02, 15, 11, 00, 00), // 15/02/12 11.00AM
new DateTime(2012, 02, 15, 12, 00, 00), // 15/02/12 12.00PM
new DateTime(2012, 02, 15, 12, 00, 00), // 15/02/12 12.00PM
new DateTime(2012, 02, 15, 01, 00, 00), // 15/02/12 01.00PM
};
var orderedDateTimes = dateTimes.OrderBy(dt => dt);