TechTalkz.com Logo

Go Back   TechTalkz.com Technology & Computer Troubleshooting Forums > Tech Support Archives > Programing Languages > C#(C Sharp)

Notices

Reply
 
Thread Tools Display Modes
Old 15-12-2007, 06:17 AM   #11
Peter Duniho
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
  Reply With Quote
Old 15-12-2007, 09:59 AM   #12
not_a_commie
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.
  Reply With Quote
Reply

Thread Tools
Display Modes


Google
 


All times are GMT +5.5. The time now is 05:58 AM.


vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO
Copyright © 2005-2008, TechTalkz.com. All Rights Reserved - Privacy Policy
Valid XHTML 1.0 Transitional