"Tom Gao" <to********@optushome.com.au> wrote in message news:<41***********************@news.optusnet.com. au>...
if I wanted to store value in a key-value pair how do I do it ? I want to
keep them in order of A C B D... so this means I can't use sortlist and I
also can't use hashtable as it means I would lose ordering
Thanks
Tom
Simply create a class that implements the IComparer interface and pass
an instance of that class to the SortedList constructor. The
SortedList will then sort the entries according to the sort order of
the keys as defined in the Compare() method of your IComparer:
private class MyKeyComparer : IComparer
{
public MyKeyComparer()
{ }
public int Compare(object x, object y)
{
string key1 = (string)x;
string key2 = (string)y;
... establish your sort order here ...
}
}
then just say:
SortedList myList = new SortedList(new MyKeyComparer());
and you have a sorted list that sorts according to the order you
defined.
}