Home All Groups Group Topic Archive Search About

How to get a KEY from a sorted list (not a VALUE) ??

Author
15 Sep 2006 4:23 PM
pamelafluente
Hi,

I have a SortedList "MySortedList". I want to get the KEY, not the
VALUE. How can i do that ?? Possibly I want a O(1) operation:


If  MySortedList.ContainsKey(SomeObject) Then

       SomeObject_ContainedKey =   MySortedList.??what????(SomeObject)

End If


PS.
Please note that SomeObject and SomeObject_ContainedKey (the one I want
to get) are *not* the same because clearly I am assuming ContainsKey
return TRUE based on some comparer.


-P

Author
18 Sep 2006 8:03 PM
Claes Bergefall
Dim index As Integer = MySortedList.IndexOfKey(SomeObject)
If index >= 0 Then
    SomeObject_ContainedKey = MySortedList.GetKey(index)
End If

   /claes

<pamelaflue***@libero.it> wrote in message
Show quoteHide quote
news:1158337387.625736.175710@d34g2000cwd.googlegroups.com...
> Hi,
>
> I have a SortedList "MySortedList". I want to get the KEY, not the
> VALUE. How can i do that ?? Possibly I want a O(1) operation:
>
>
> If  MySortedList.ContainsKey(SomeObject) Then
>
>       SomeObject_ContainedKey =   MySortedList.??what????(SomeObject)
>
> End If
>
>
> PS.
> Please note that SomeObject and SomeObject_ContainedKey (the one I want
> to get) are *not* the same because clearly I am assuming ContainsKey
> return TRUE based on some comparer.
>
>
> -P
>