Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Descending SortedList
Message
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01396377
Message ID:
01396613
Views:
62
Yes it works, it needed "System.Collections.Generic.IComparer" as Viv suggested.
...
using System.Collections;
using System.Collections.Generic;
...

public class DecendingDateCompare : System.Collections.Generic.IComparer<DateTime>
{
	public int Compare(DateTime x, DateTime y)
	{
		return x.CompareTo(y) * -1;
	}
}
A sample code to test:
...
using System.Collections;
using System.Collections.Generic;
...
SortedList<DateTime, int> aSortedList = new SortedList<DateTime, int>(new DecendingDateCompare());
aSortedList.Add(DateTime.Now.AddDays(-10), 100);
aSortedList.Add(DateTime.Now.AddDays(10), 10);
aSortedList.Add(DateTime.Now.AddDays(-5), 90);
aSortedList.Add(DateTime.Now.AddDays(5), 20);
aSortedList.Add(DateTime.Now.AddDays(-3), 80);
aSortedList.Add(DateTime.Now.AddDays(3), 30);

StringBuilder sb = new StringBuilder();
IDictionaryEnumerator iDicEnum = (IDictionaryEnumerator) aSortedList.GetEnumerator();
while( iDicEnum.MoveNext() )
	sb.AppendLine( iDicEnum.Key.ToString() + ", " + iDicEnum.Value.ToString() );
	
MessageBox.Show(sb.ToString());
>Hi,
>As mentioned I didn't give *any* thought to the logic in the return line. My guess is that, as it stands, it would give ascending rather than descending order and so will need to be adjusted...
>Best,
>Viv
>>Thanks!! That gets me through the compile. I'll let you know if it works to sort the list the way I need it to...
>>
>>bob
Previous
Reply
Map
View

Click here to load this message in the networking platform