I’m trying to sort a dictionary by value with LINQ but I can’t figure how the ToDictionary() method works.
All the examples I can find are in c#.
here’s my code
Dim f As Dictionary(Of String, String) = (From value In projectDescriptions.Values
Order By value Ascending
Select value).ToDictionary(???)
UPDATE
Finally, I just realized that was stupid. Sorry
I did a list (of keyValuePair(of string,string))
And to sort my list, I do
mylist.OrderBy(Function(x) x.Value).ToList()
hope it will help someone
You said you didn’t find an example of this, but check MSDN here. Something like the following should work in VB.
But if you store a sorted enumerator in a dictionary again, it becomes unsorted, that’s a property of a dictionary or map in general and is precisely why dictionaries are so fast and popular. If you need it sorted, perhaps you want to use
SortedDictionaryinstead?