|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
OrderedDictionary - to retrieve objects in same orderHi,
I want to use OrderedDictionary to get my objects in same order as they are inserted in. I also want to access the objects using a key. So my question is whether this is the best option or there is some better collection object than OD. The current MSDN documentation dosn't says anything in favor or against OD for retrieving object in order. Remember I don't want ot sort objects on keys or anything else. Thanks in advance, Suhaib Good question. The documentation for this class is very cryptic about how it
is "ordered." I can't tell for sure whether it is ordered internally (which I doubt) or simply by the enumerator. The examples are bad in that when they demonstrate getting the values in the OrderedDictionary by Keys, they use a list that has been entered in non-alphabetical order, but when they demonstrate getting the values using an enumerator, they enter the list items in alphabetical order, thus muddying the waters as to why the items came back *out* in alphabetical order. The text is not clear about this. However, some experiments should answer the questions for you. I would imagine that the items are added to the list in the order in which they were actually added, and that when you get the keys by copying, the order is not changed, which would satisfy your requirements. I would also guess (with less confidence) that using an enumerator sorts the items. But again, it shouldn't be hard to set up a test for this. -- Show quoteHTH, Kevin Spencer Microsoft MVP Professional Chicken Salad Alchemist Big thicks are made up of lots of little thins. "Suhaib" <Suh***@discussions.microsoft.com> wrote in message news:F130129F-BBF0-4B9C-BBCD-A0657D6D2FB9@microsoft.com... > Hi, > I want to use OrderedDictionary to get my objects in same order as they > are inserted in. I also want to access the objects using a key. So my > question is whether this is the best option or there is some better > collection object than OD. The current MSDN documentation dosn't says > anything in favor or against OD for retrieving object in order. > > Remember I don't want ot sort objects on keys or anything else. > > Thanks in advance, > Suhaib Check out the Power Collections library at www.wintellect.com. Lots of
generic goodness there... Show quote "Suhaib" wrote: > Hi, > I want to use OrderedDictionary to get my objects in same order as they > are inserted in. I also want to access the objects using a key. So my > question is whether this is the best option or there is some better > collection object than OD. The current MSDN documentation dosn't says > anything in favor or against OD for retrieving object in order. > > Remember I don't want ot sort objects on keys or anything else. > > Thanks in advance, > Suhaib |
|||||||||||||||||||||||