Edit
The ToDictionary()
method has an overload that takes two lambda expressions (nitpick: delegates); one for the key and one for the value.
For example:
var myDic = GetSomeStrings().ToDictionary(x => x, x => x.Number('A'));
Note that the values returned by GetSomeStrings()
must be unique.
.Net’s Dictionary<TKey, TValue>
is unordered; it cannot be sorted at all.
Instead, you can sort the dictionary when you use it, like this:
foreach(KeyValuePair<string, int> kvp in dict.OrderBy(kvp => kvp.Value))