您如何将此linq表达式的选择部分专门转换为lambda?
var query2 = from method in typeof(double).GetMethods() // integrated method c# reflection
orderby method.Name
group method by method.Name into groups
select new { MethodName = groups.Key, NumberOfOverloads = groups.Count()};
到目前为止我有这个:
var methods = typeof(double).GetMethods();
var query3 = methods.OrderBy(x => x.Name).GroupBy(y => y.Name);
我为选择尝试了这个但是我得到了compilor错误。
var query3 = methods.OrderBy(x => x.Name).GroupBy(y => y.Name)
.Select<new { MethodName = groups.Key, NumberOfOverloads = groups.Count()}>();
非常感谢帮助谢谢。
答案 0 :(得分:7)
这是确切的翻译。我不知道为什么你需要OrderBy
tho,考虑到你没有使用Select
var methods = typeof(double).GetMethods()
.OrderBy(x=>x.Name)
.GroupBy(x=>x.Name)
.Select(x=> new { MethodName = x.Key, NumberOfOverloads = x.Count()});
获得了相同的结果
var methods = typeof(double).GetMethods()
.GroupBy(x=>x.Name)
.Select(x=> new { MethodName = x.Key, NumberOfOverloads = x.Count()});
并且您节省了一些计算时间,因为您不必订购该集合。