开发者

How to order a list by date (and/or minute and seconds) in C#

I need to order a list of elements by date.

This lamba function works well, but if two 开发者_运维知识库elements have the same date it doesn't.

orderList.Sort((x, y) => y.Value.CreationDate.CompareTo(x.Value.CreationDate));

where CreationDate is a DateTime value.

Suppose, for example, that two elements have the same creation date (09/05/2011). I would be able to distinguish minute (or maybe seconds).

Thank you in advance.


DateTime already contains the hours, minutes and seconds. If they are not available in your CreationDate value, then there is nothing you can sort based on. If, in fact, the data is there, than you should have no problem sorting as it is.


You can use DateTime Struct

As it implement IComparable you don't need that lambda, only call orederList.Sort()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜