Forum Moderators: open

Message Too Old, No Replies

sorting an associative array?

I can do it in PHP...

         

httpwebwitch

7:38 pm on Apr 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry this will seem like a newb question

This is something I can do in PHP, but now I need to do it in C#

I have a list of keys and vales, like:
myarray['happy']=4
myarray['sad']=5
myarray['glum']=7
myarray['giddy']=2

I want to sort them in order and show them as a list:
glum (7)
sad (5)
happy (4)
giddy (2)

How do I do that in C#?

CaseyRyan

8:35 pm on Apr 11, 2005 (gmt 0)

10+ Year Member



You should investigate using the System.Collections.SortedList [msdn.microsoft.com] or one of the other collection objects. They are equivalient to the associative arrays of PHP.

You'll prolly want to google sortedlist c#

I don't have any sample code unfortuneatly. Perhaps someone else could post some.

-=casey=-