按照按顺序排序按c#中的创建日期和文件时间排序 [英] Sorting in Accesending Order By creation date and Time of File in c#
本文介绍了按照按顺序排序按c#中的创建日期和文件时间排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
请关注我这个
按照开始顺序排序按创建日期和文件时间在c#中。
GetFiles()。OrderBy(p => p.CreationTime.ToString(yyyy-MM-dd HH:mm:ss.fff,CultureInfo.InvariantCulture))
i am使用此代码
但是我的创作时间相同
如12.44
12.44
hi
please haelp me on this
Sorting in Accesending Order By creation date and Time of File in c#.
GetFiles().OrderBy(p => p.CreationTime.ToString("yyyy-MM-dd HH:mm:ss.fff", CultureInfo.InvariantCulture))
i am using this code
but iam getting Creation time same
like 12.44
12.44
推荐答案
如果您想按日期订购文件,为什么要将日期转换为字符串,然后尝试按顺序排序?
只需订购直接DateTime字段,并且无需转换。
至于你的奇怪位:
但是我得到了创造时间相同
如12.44
12.44是的,你会 - 如果两个文件创建的时间相似,则OrderBy不会删除它们。如果你想删除具有相同创建时间的文件,你也必须对它们使用Distinct - 但这意味着创建一个EqualityComparer:
http://msdn.microsoft.com/en-us/library/bb338049(v = vs.110)的.aspx 一> [ ^ ] - 并且无法确定哪两个文件是保留在输出列表中的文件。
If you want to order files by date, why do you convert the date to a string, and then try to order by that?
Just order by the DateTime field directly, and there is no need to convert.
As for your odd bit:
"but iam getting Creation time same
like 12.44
12.44"Yes, you will - if two files are created as a similar time, OrderBy does not remove them. If you want to remove files with the same creation time, you will have to use Distinct on them as well - but that means creating an EqualityComparer:
http://msdn.microsoft.com/en-us/library/bb338049(v=vs.110).aspx[^] - and there is no way to decide which of the two files is the one to keep in the output list.
这篇关于按照按顺序排序按c#中的创建日期和文件时间排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文