Detect smallest number inside a dictionnary

PhilippeRenaud
PhilippeRenaud used Ask the Experts™
on
Hello EE,

I have a dictionnary i vb.net    (Of Integer, Double)

looks like this:

(1, 4.8583)
(2, 0.9834)
(3, 11.4945)

etc.


I need to detect the smallest double inside the dictionnary. here it would be 0.9834

how can I compare all the dict and find it ?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2011

Commented:
Please try:
Dim minValue As Double = yourDictionary.Values.Min()

Open in new window

Author

Commented:
and if I want the key of that one ?
Top Expert 2011
Commented:
It should be:
Dim minKey = yourDictionary.First( Function(e) e.Value = yourDictionary.Values.Min()).Key

Open in new window

Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Mike TomlinsonHigh School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
Top Expert 2009

Commented:
Another way:

        Dim data As New Dictionary(Of Integer, Double)
        data.Add(1, 4.8583)
        data.Add(2, 0.9834)
        data.Add(3, 11.4945)

        Dim min = (From entry In data Select entry Order By entry.Value Ascending).First
        MessageBox.Show("Key: " & min.key & " / Value: " & min.value)

Author

Commented:
Perfect

Author

Commented:
True idle_mind, just clicked accept before seeing your comment...

but thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial