LINQ - Aggregate() 簡單測試
https://msdn.microsoft.com/zh-tw/library/bb548744(v=vs.110).aspx
seed:指定 func 內第一個引數的初始值
func:集合內各項目處理程式
resultSelector:func 處理完畢後的處理程式
var numbers = new List<int> { 6, 2, 8, 3 };
decimal tmp = numbers.Aggregate(
seed: 0,
func: (result, item) => result + item,
resultSelector: result => (decimal)result / numbers.Count);
Console.WriteLine(tmp);
https://msdn.microsoft.com/zh-tw/library/bb549218%28v=vs.110%29.aspx
指定起始值,直接回傳 func 第一個引數的值
var numbers = new List<int> { 6, 2, 8, 3 };
decimal tmp = numbers.Aggregate(
seed: 0,
func: (seed, item) => seed + item);
Console.WriteLine(tmp);
https://msdn.microsoft.com/zh-tw/library/bb548651%28v=vs.110%29.aspx
不指定起始值,直接回傳 func 第一個引數的值
var numbers = new List<int> { 6, 2, 8, 3 };
decimal tmp = numbers.Aggregate(
func: (seed, item) => seed + item);
Console.WriteLine(tmp);