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);
原文地址:https://www.cnblogs.com/zhm001/p/11599479.html
时间: 2024-10-12 01:55:27