问题描述
我创建的日期值的CSV数组,现在需要能够对它们进行排序,这样我可以再拿到从数组的最后日期。
我曾尝试:
的Array.Sort()
但是,这并不正确排序,我想因为数组值是字符串,任何身体有什么想法?
感谢您的帮助。
code用于创建ARRAY
字符串数组exampel:19/07 / 2012,23 / 07 / 2012,23 / 07 / 2012,19 / 07 / 2012,25 / 07/2012
昏暗ArrDates作为数组= ArrDates .Split()
SOLUTION
昏暗ArrAgentsReportCheck为ARRAY = AgentsReportCheck.Split()昏暗ArrDates作为新的列表(过期)
对于我作为整数= 0〜ArrAgentsReportCheck.Length - 1
ArrDates.Add(ArrAgentsReportCheck(I))
下一个ArrDates.Sort()
昏暗LatestDate为日期= ArrDates.Max()
由于astander说,这是非常复杂的一个数组有日期时间值排序。相反,只是转换阵列列出或ArrayList和让您的生活更轻松。
有关ArrayList中,你可以使用下面的语法:
列表<&日期时间GT;日期= ... //初始化并填写
dates.Sort();
dates.Reverse();
I have created an array from a CSV of date values and now need to be able to sort them so that I can then get the latest date from the array.
I have tried:
Array.Sort()
but this doesn't sort correctly, I suppose because the array values are strings, any body got any ideas??
Thanks for any help.
CODE USED TO CREATE ARRAY
'array string exampel: "19/07/2012,23/07/2012,23/07/2012,19/07/2012,25/07/2012"
Dim ArrDates As Array = ArrDates .Split(",")
SOLUTION
Dim ArrAgentsReportCheck As Array = AgentsReportCheck.Split(",")
Dim ArrDates As New List(Of Date)
For i As Integer = 0 To ArrAgentsReportCheck.Length - 1
ArrDates.Add(ArrAgentsReportCheck(i))
Next
ArrDates.Sort()
Dim LatestDate As Date = ArrDates.Max()
As astander said, It is very complicated to sort a array having datetime values. Instead just convert the array to List or ArrayList and make your life easy.
For ArrayList you can use the following syntax:
List<DateTime> dates = ... // init and fill
dates.Sort();
dates.Reverse();
这篇关于日期排序的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!