I have a block of codes here:
SortedList<char, int> alpha = new SortedList<char, int>();
List<string> A = new List<string>();
alpha.OrderByDescending(x => x.Value);
foreach (var a in alpha)
A.Add(a.Key + ":" + a.Value);
-
alpha.OrderByDescending(x => x.Value);doesn’t sort by value, but sorts by key. May I know what’s the problem with the code? -
can I simplify:
foreach (var a in alpha)
A.Add(a.Key + ":" + a.Value);
into one lambda statement? something like
alpha.ForEach(x => A.Add(a.Key + ":" + a.Value));
This might help: