日期:2014-05-20 浏览次数:20753 次
public void Linq93() { double startBalance = 100.0; int[] attemptedWithdrawals = { 20, 10, 40, 50, 10, 70, 30 }; double endBalance = attemptedWithdrawals.Aggregate(startBalance, (balance, nextWithdrawal) => ((nextWithdrawal <= balance) ? (balance - nextWithdrawal) : balance)); Console.WriteLine("Ending balance: {0}", endBalance); }
/* (100,20)=> 100-20=80 (80,10) => 80-10=70 (70,40) => 70-40=30 (30,50) => 30 (30,10) => 30-10=20 (20,70) => 20, (20,30) => 20 */
------解决方案--------------------