sorted List

G

Guest

Hi,

I am using a sorted List to add dates to it.
It appears that the dates aren't getting sorted.
Is it that sorted Lists cannot work with dates when it comes to sorting???


PK
 
K

Karl Seguin

This works for me:
SortedList sl = new SortedList();
sl.Add(DateTime.Now.AddHours(1), "4");
sl.Add(DateTime.Now.AddHours(2), "5");
sl.Add(DateTime.Now.AddHours(3), "6");
sl.Add(DateTime.Now.AddHours(-3), "1");
sl.Add(DateTime.Now.AddHours(-2), "2");
sl.Add(DateTime.Now.AddHours(-1), "3");

for (int i = 0; i < sl.Count; ++i)
{
Response.Write(sl.GetKey(i));
}

What's not working for you?

Karl
 
G

Guest

Hi,
I was expecting it to sort on values but l got that it sorts on keys.
Is there a way I can make it sort on values and not on keys?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top