linq 这几天用到的知识点,记录一下加强印象。
时间:2010-11-26 来源:eric john
Dictionary<string,double> dic = new Dictionary<string,double>();
dic.Add(key,double)
...
var sortdic =from d in dic order by d.value descending select d ;
2.Linq ToDictionary()方法的使用
接上。
Dictionary<string ,double> dic2 = sortdic.ToDictionary(c=>c.key,c=>c.value);
3.复合的排序,根据排好顺序的keys对字典排序。
List<string> sortkeys = List<string>();
Dictionary<string,double> dic = new Dictionary<string,double>();
dic.Add(key,double)
...
var sortdic = from s in sortkeys
join pair in (from pair in dic select pair)
on s equals pair.Key
select pair;
Dictionary<string,double> dic2 = sortdic.ToDictionary(c=>c.key,c=>c.value);