I have a shopping cart that I iterate through in a foreach loop. Each Item in the cart needs to be added to an orderItemList array.
orderItemList =
[{
orderItemId = 1,
quantity = 2
},{
orderItemId = 2,
quantity =1
}]
So I was trying to use
foreach(var items in shoppingCart)
{
var newOrderItems = new[]
{ new orderItem { orderItemId = item.Id , quantity = item.quantity }
};
It is only adding the last item in the cart. It loops through and creates each one but only the last one is added. What am i missing?
newOrderItems only returns the one item even though it loops.