I am trying to create an array or a list where I can put a numeric value together with a string and sort it by the numeric value. I understand how to sort the list. What I can't figure out is how to put the two values together in a container where I can work with them.
The code below produces results like this
- 0 / 11
- 112.312579750842 / 15
- 2.218114802558 / 16
- 416.368892799685 / 19
- 97.820969866657 / 24
Obviously the ArrayList is treating everything like a string so I am not able to sort these results numerically. What can I use in place of an ArrayList to get to where I need to be?
Dim myLong As String = "-56.5896612"
Dim myLat As String = "23.2266818"
Dim Results As New Generic.Dictionary(Of String, Double)
Dim row As DataRow
For Each row In BO.DAC.ExecuteDataTable("GeoLocationSelect").Rows
Dim miles As Double = (Radius.CalcDistance(myLat, _
myLong, _
CStr(row("Lat")), _
CStr(row("Lon"))))
Results.Add(String.Format("{0} / {1}", miles, row("Store")))
Next
' Updated. I added this below code, which i lifted from the link Brain2000
' posted. I do see my key pair in the debugger listing out correctly but
' I am unsure of how to get a hold of them now.
Dim sortedDict = _
(From entry In Results Order By entry.Value Ascending).ToDictionary(Function(pair) pair.Key, _
Function(pair) pair.Value)
For Each res In sortedDict
' How do I get to the values here (for instance to write that key value pair out to the debug windows).
Next