We help IT Professionals succeed at work.

"peeking" into a sorted dictionary (vb.net)

larrysy
larrysy used Ask the Experts™
on
Is there a way to "peek" into a sorted dictionary in the same way as the queue collection?  I don't know the value of the keys, but I want to check the item with the smallest key.  Or, is there another way.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009
Commented:
See the SortedDictionary.Values() property:
http://msdn.microsoft.com/en-us/library/zazzsd83.aspx

    "The values in the SortedDictionary(TKey, TValue).ValueCollection are sorted according to the Comparer property, and are in the same order as the associated keys in the SortedDictionary(TKey, TValue).KeyCollection returned by the Keys property."

So you can just do:

        Dim sd As New SortedDictionary(Of String, Integer)
        ...
        Debug.Print(sd.Values(0))

Author

Commented:
Thanks,  I don't know if the sorted dictionary is the best solution for my problem but I'll ask it in another question.