I have a foreach loop that loops through items in a collection. Is it possible to re-use properties of an element if that item already exists? For example:
foreach(example item in creditItems)
{
item.Total += item.Quantity;
}
Let's assume there are 3 items in creditItems
. The first item and the third item are the same, at least they are supposed to be. The problem is they are considered completely different items(and understandably so). The problem with this is when it loops through to the last item, item.Quantity
doesn't add to the original item.Total
because since it's considered a new item, total is 0 + item.Quantity
. Is my logic just off?