c# 字典 Dictionary排序问题现有字典Dictionary dic = new Dictionary();dic.Add("bca",new List(){"xkyz"} );dic.Add("c",new List(){"xdz"} );dic.Add("absdc",new List(){"xyz"} );dic.Add("dxzcu",new List(){"fyz"} );排序依据字典健的长度来排序,越长的越在前面,列表的值不变只改变顺序Dictionary dic = new Dictionary();dic.Add("dxzcu",new List(){"fyz"} );dic.Add("absdc",new List(){"xyz"} );dic.Add("bca",new List(){"xkyz"} );dic.Add("c",new List(){"xdz"} );

问题描述:

c# 字典 Dictionary排序问题
现有字典
Dictionary dic = new Dictionary();
dic.Add("bca",new List(){"xkyz"} );
dic.Add("c",new List(){"xdz"} );
dic.Add("absdc",new List(){"xyz"} );
dic.Add("dxzcu",new List(){"fyz"} );
排序依据字典健的长度来排序,越长的越在前面,列表的值不变只改变顺序
Dictionary dic = new Dictionary();
dic.Add("dxzcu",new List(){"fyz"} );
dic.Add("absdc",new List(){"xyz"} );
dic.Add("bca",new List(){"xkyz"} );
dic.Add("c",new List(){"xdz"} );

return dic.OrderByDescending(r => r.Key).ToDictionary(r => r.Key,r => r.Value);