Given a setup like this ..
class Product { int Cost; // other properties unimportant } var products = new List { new Product { Cost
Use a captured variable to track the amount taken so far.
int sum = 0; IEnumerable query = products.TakeWhile(p => { bool canAfford = (sum + p.Cost) <= credit; sum = canAfford ? sum + p.Cost : sum; return canAfford; });