码迷,mamicode.com
首页 > 编程语言 > 详细

C# 嵌套字典排序

时间:2019-09-27 19:39:00      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:嵌套   code   esc   tin   nbsp   写法   rom   value   key   

linq两种写法,如下所示:

1.

var resultInformation = from outer in userInformation
                        from inner in outer.Value
                        let data = new { Outer = outer.Key, Inner = inner.Key, Value = inner.Value }
                        orderby data.Outer, data.Inner, data.Value
                        select data;

2.

var resultInformation = 
    from student in userInformation
    orderby student.Key
    select new
    {
        studentId = student.Key,
        courses = 
            from courseScore in student.Value
            orderby courseScore.Value descending
            select new {
                course = courseScore.Key,
                score = courseScore.Value
            }
    };

等价写法:

var resultInformation = userInformation
    .SelectMany(i => i.Value, (key, inner) => new { Outer = key, Inner = inner.Key, Value = inner.Value})
    .OrderBy(e => e.Outer)
    .ThenBy(e => e.Inner)
    .ThenBy(e => e.Value);

 

C# 嵌套字典排序

标签:嵌套   code   esc   tin   nbsp   写法   rom   value   key   

原文地址:https://www.cnblogs.com/zhm001/p/11599479.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!