帮忙解释一下这段的意思!!!!

koumingjie 2011-06-03 10:39:52

IList<int> datasource = new List<int>();

datasource.Add(1);

datasource.Add(2);

datasource.Add(7);

datasource.Add(3);

datasource.Add(3);

datasource.Add(4);

datasource.Add(5);

datasource.Add(5);


IList<int> datasource2 = new List<int>();

datasource2.Add(1);

datasource2.Add(2);

datasource2.Add(7);

datasource2.Add(3);

datasource2.Add(3);

datasource2.Add(4);

IList<IList<int>> collection = new List<IList<int>> { datasource, datasource2 };


//----------------------这两句的意思--------------------------------
bool isExist = collection.Aggregate(false, (prev, x) => prev ? prev : x.Any(y => y == 5));


bool isExist1 = collection.Aggregate(true, (prev, x) => prev ? x.Any(y => y == 5) : prev);





帮忙解释一下以下两句的意思,越详细越好

bool isExist = collection.Aggregate(false, (prev, x) => prev ? prev : x.Any(y => y == 5));


bool isExist1 = collection.Aggregate(true, (prev, x) => prev ? x.Any(y => y == 5) : prev);
...全文
140 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
v_yao 2011-06-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mockqi 的回复:]

三元 Linq

完毕。。。
[/Quote]
+++
精辟
天下如山 2011-06-03
  • 打赏
  • 举报
回复
555555 为嘛我看不懂 555555
huangwenquan123 2011-06-03
  • 打赏
  • 举报
回复
对序列应用累加器函数,提取第一个元素作为初始化累计结果,然后循环遍历其他元素,并依次调用 func 委托进行累计操作。func 有两个参数,第一个参数为上一次 func 的执行结果,第二个参数为要处理的集合元素
bool isExist = collection.Aggregate(false, (prev, x) => prev ? prev : x.Any(y => y == 5));
这里的prev都是为正整数,永远都为true,所以prev ? prev : x.Any(y => y == 5));永远都是prev,为true;

bool isExist1 = collection.Aggregate(true, (prev, x) => prev ? x.Any(y => y == 5) : prev);prev 还是一样永远都为true,所以执行x.Any(y => y == 5),x的结果集是datasource ,datasource 2
第一次遍历datasource 的时候有等于5所以为true,第二次遍历datasource2的结果集中没有等于5所以为false,最后返回false
anbam 2011-06-03
  • 打赏
  • 举报
回复
The Aggregate<TSource, TAccumulate, TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>) method makes it simple to perform a calculation over a sequence of values. This method works by calling func one time for each element in source. Each time func is called, Aggregate<TSource, TAccumulate, TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>) passes both the element from the sequence and an aggregated value (as the first argument to func). The value of the seed parameter is used as the initial aggregate value. The result of func replaces the previous aggregated value. The final result of func is passed to resultSelector to obtain the final result of Aggregate<TSource, TAccumulate, TResult>(IEnumerable<TSource>, TAccumulate, Func<TAccumulate, TSource, TAccumulate>, Func<TAccumulate, TResult>).

子夜__ 2011-06-03
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 koumingjie 的回复:]

引用 1 楼 mockqi 的回复:
三元 Linq

完毕。。。


人才啊,太精炼了
[/Quote]
哈哈 我C 太搞笑了啊

喷了。。。。。吃饭去了。。。
koumingjie 2011-06-03
  • 打赏
  • 举报
回复
不会就一个人回答了吧
koumingjie 2011-06-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 mockqi 的回复:]
三元 Linq

完毕。。。
[/Quote]

人才啊,太精炼了
  • 打赏
  • 举报
回复
三元 Linq

完毕。。。
koumingjie 2011-06-03
  • 打赏
  • 举报
回复
沉了!!!!!!!!!!!!!!!!!!!!!!!!!
koumingjie 2011-06-03
  • 打赏
  • 举报
回复
csdn人才血多
koumingjie 2011-06-03
  • 打赏
  • 举报
回复
别整天精辟了,受不了

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧