//group 分组
var queryGroups =
from score in scores
group score by score;
//into 存储查询的内容
percentileQuery is an IEnumerable<IGrouping<int, Country>>
var percentileQuery =
from score in scores
group score by score into scorequery
where scorequery.Key > 10
select scorequery;
//在 from 开始子句以及 select 或 group 结束子句之间,
//所有其他子句(where、join、orderby、from、let)都是可选的。
//任何可选子句都可以在查询正文中使用零次或多次。
//let 子句
//使用 let 子句可以将表达式(如方法调用)的结果存储到新的范围变量中。
string[] names = { "a n", "b c", "c n", "d m" };
IEnumerable<string> queryFirstNames =
from name in names
let firstName = name.Split(new char[] { ' ' })[0]
select firstName;
//对一个序列应用累加器函数。
//Aggregate<TSource>(IEnumerable<TSource>, Func<TSource, TSource, TSource>)
string sentence = "the quick brown fox jumps over the lazy dog";
string[] words = sentence.Split(' ');
string reversed = words.Aggregate((wording, next) => wording + " " + next);
Console.WriteLine(reversed);
Linq-Enumerable类
最新推荐文章于 2025-03-05 07:00:00 发布