From the following simulation
int[] amountWithdrawal = { 10, 20, 30, 140, 50, 70 };
amountWithdrawal.Aggregate(100, (balance, withdrawal) =>
{
Console.WriteLine("balance :{0},Withdrawal:{1}", balance, withdrawal);
if (balance >= withdrawal)
{
return balance - withdrawal;
}
else return balance;
}
);
I want to terminate the Aggregation when the balance is less than the withdrawal
.But my code travels the entire array.How to terminate it?