1.SelectMany 用于建立 两个集合的对应关系
2.Aggregate 进行迭代(如果不提供种子,那么第一个元素就是种子)
var aa = new string[] { "aa1","aa2" };
var bb = new string[] { "bb1","bb2","bb3"};
//a => bb 表明集合aa 和 结合bb 建立迪科尔乘积
var s1 = aa.SelectMany(a => bb,(a,b) => a + "->"+b)
//如果提供了种子,种子就是第一个元素
.Aggregate("Header;",(curr,next) => curr + next + ";")
.ToArray();
//Header;aa1->bb1;aa1->bb2;aa1->bb3;aa2->bb1;aa2->bb2;aa2->bb3;
Console.WriteLine(s1);
s1 = aa.SelectMany(a => bb, (a, b) => a + "->" + b)
.Aggregate( (curr, next) => curr + next + ";")
.ToArray();
//如果没有种子,第一个元素就是种子
//aa1->bb1aa1->bb2;aa1->bb3;aa2->bb1;aa2->bb2;aa2->bb3;
Console.WriteLine(s1);
s1 = aa.SelectMany(a => bb, (a, b) => a + "->" + b)
.Aggregate((curr, next) => curr + ";" + next )
.ToArray();
//如果没有种子,第一个元素就是种子
//aa1->bb1;aa1->bb2;aa1->bb3;aa2->bb1;aa2->bb2;aa2->bb3
Console.WriteLine(s1);
string[] fruits = { "apple", "mango", "orange", "passionfruit", "grape" };
// Determine whether any string in the array is longer than "banana".
string longestName =
fruits.Aggregate("banana",
(longest, next) =>next.Length > longest.Length ? next : longest,
// Return the final result as an upper case string.
fruit => fruit.ToUpper());
Console.WriteLine("The fruit with the longest name is {0}.",longestName);
// The fruit with the longest name is PASSIONFRUIT.
// Determine whether any string in the array is longer than "banana".
//未提供种子,第一个元素就是种子了
longestName = fruits.Aggregate((longest, next) => next.Length > longest.Length ? next : longest);
Console.WriteLine("The fruit with the longest name is {0}.", longestName);
// The fruit with the longest name is PASSIONFRUIT.