1 public MainWindow()
2 {
3 InitializeComponent();
4 int a = 100;
5 this.initList ( a );
6 testLinq();
7 }
8 List<int> listNum = new List<int>();
9
10 void initList ( int iFlag )
11 {
12
13 for ( int i = 1; i < iFlag; i++ )
14 {
15 listNum.Add ( i );
16 }
17 }
18 void testLinq()
19 {
20 Func<int, int , int> functest = ( i, j ) =>
21 {
22 return i + j;
23 };
24
25 int testNum = listNum.Aggregate ( functest );
26 testNum = listNum.Aggregate ( ( m, n ) => m + n );
27 int testNumAdd = listNum.Aggregate ( 0, ( total, next ) => next % 2 == 0 ? total + 1 : total );
28 int testNumAddOpreation = listNum.Aggregate ( 0, ( total, next ) => next % 2 == 0 ? total + 1 : total, fruit => fruit + 100 );
29 }
testNum = listNum.Aggregate ( ( m, n ) => m + n );指定的两列做指定的操作
int testNumAdd = listNum.Aggregate ( 0, ( total, next ) => next % 2 == 0 ? total + 1 : total );在给定的参数上来判断列表的每一个值,然后进行相应的操作。
int testNumAddOpreation = listNum.Aggregate ( 0, ( total, next ) => next % 2 == 0 ? total + 1 : total, fruit => fruit + 100 );在上一个方法的基础上,再传一个委托来实现结果的过滤。