![]() |
|
|
#11 |
|
Guest
Posts: n/a
|
Re: get original key object from dictionary
On Fri, 14 Dec 2007 15:40:57 -0800, Marc Gravell <marc.gravell@gmail.com>
wrote: >> ... something that's bugged me about the Dictionary<> and similar >> classes >> ... but you cannot get the ordinal index of that key related to the >> collection, given the key. > > Well, you can for SortedList, but that's about it... ;-( Yes, but why only that one? For SortedDictionary, I understand. The underlying implementation is a binary tree, not an array. But the docs say that Dictionary has the same basic behavior as SortedList (that is, the Keys collection is a wrapper around the original data). Not all of the collection classes would lend themselves to having an IndexOfKey() method, but I'm not really clear on why it's not on every class where it apparently would make sense. Pete |
|
|
|
#12 |
|
Guest
Posts: n/a
|
Re: get original key object from dictionary
Yes, I suppose that looping is the only way to do it. Thanks for all
your comments. I have some objects that use Guids for their uniqueId, their hashcode, and their equals. It's easy to make a stubbed instance of the class and use that as a lookup for a value if all you have is a Guid. Then you just keep a static reference to it and change the Guid on it when you need to do a lookup by Guid. However, it didn't work cleaning for looking up the original keys. |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|