This is an offshoot of this question. Consider data thus:
1/1/2000 10000
1/1/2001 10000
1/1/2002 10000
10/1/2003 11000
1/1/2004 11000
1/1/2005 11000
6/1/2006 10000
9/1/2006 12000
This data is being collected into a SortedDictionary
with the dates as the keys. I would like to convert it into this format:
1/1/2000 10000
10/1/2003 11000
6/1/2006 10000
9/1/2006 12000
That is, I want the earliest dated item for any given unique value. Normally when I'm presented with this sort of problem, I would iterate backwards...
for i = items.count - 1 to 1 step -1
if item(i) is like item(i-1) remove item(i)
next
But how do you do that with a SortedDictionary
? Linq provides a reverse enumerator, and an index-ish thing, but Linq is only available on Windows. Is there an easy way to do this within basic VB.net I am unfamiliar with?
I solved this by making a List(Of Date)
, iterating backwards over that, then removing entries from the List
. Then I iterate over the result and remove any key from the SortedDictionary
. But that's seriously ugly and many more lines than I would like.