I have this code:
List<KeyValuePair<String,List<MyObject>>> aux = retEmpty.ToList();
aux.ForEach(x => ret.Add(x.Key, x.Value));
I need to sort "ret" by the first element("string"). I tried a couple example but none of them work. Any help?
I have this code:
List<KeyValuePair<String,List<MyObject>>> aux = retEmpty.ToList();
aux.ForEach(x => ret.Add(x.Key, x.Value));
I need to sort "ret" by the first element("string"). I tried a couple example but none of them work. Any help?
Did you try replacing the second line with:
aux.OrderBy(x=>x.Key).ToList().ForEach(x=>ret.Add(x.Key,x.Value));
?
Based on your comment you can simply use a SortedDictionary
var ret = new SortedDictionary<String,List<MyObject>>();
ret.Add(...
Did you try something like:
var v = from obj in ret
orderby obj.Key
select obj
ret looks like a Dictionary. If this assumption is correct you could use a SortedDictionary instead.