20-10-16, 04:24 AM
Sort Dictionary based on keys
عندى كود مثل هذا
هذا الكود يتم ترتيب items ترتيب تصاعديآ لاكن هل يمكن ترتيب items معينة بمعنى
يتم اضافة one و four مثل هذا بعد ذلك يتم الترتيب مثل هذا
four
one
two
three
five
six
seven
هل يمكن ؟
عندى كود مثل هذا
كود :
Dim myDict As New Dictionary(Of String, String)
myDict.Add("one", 1)
myDict.Add("four", 4)
myDict.Add("two", 2)
myDict.Add("three", 3)
Dim sortedDict = (From entry In myDict Order By entry.Value Ascending).ToDictionary(Function(pair) pair.Key, Function(pair) pair.Value)
For Each entry As KeyValuePair(Of String, String) In sortedDict
Console.WriteLine(String.Format("{0,10} {1,10}", entry.Key, entry.Value))
Next
هذا الكود يتم ترتيب items ترتيب تصاعديآ لاكن هل يمكن ترتيب items معينة بمعنى
يتم اضافة one و four مثل هذا بعد ذلك يتم الترتيب مثل هذا
four
one
two
three
five
six
seven
هل يمكن ؟