So I just finished this lecture on completing a transaction, and I googled the error I got before watching the rest of the video to see how y’all solved it. The top solution was simply this:
foreach(InventoryItem item in transaction.Keys.ToList())
{
int quantity = transaction[item];
for (int i = 0; i < quantity; i++)
{
bool success = shopperInventory.AddToFirstEmptySlot(item, 1);
if(success)
{
AddToTransaction(item, -1);
}
}
}
I tried it out and it worked flawlessly, and had the benefit of being far less extra code to write. So, I’m wondering if there’s an issue with this solution that I’m not looking far enough ahead to be able to see?
ETA: To clarify, the code itself was not posted on the internet as a solution, but the idea of converting ToString before enumerating on a collection you need to edit was, and I tried it.