我有一個StockMultibuy
項目的列表,並正在建立這些項目的列表。列表中的一些項目我想要具有與現有項目不同的屬性,因此我嘗試創建項目的新實例,更改了我想要的屬性,然後將其添加到列表中。我不希望這會更新已經在列表中的項目。這是預期的行爲?我能做些什麼來克服這一點?應該將新項目添加到列表中<>更新列表中的以前項目嗎?
感謝
StockMultibuy aNewItem = StaticLists.GetStockMultibuyForBarcode(sBarcode);
// If we've got enough items to qualify, then add a free item
if (Reward.StockItemsTaken.Count % (Reward.FreeWhenQualified + Reward.QualifyingQty)
== Reward.QualifyingQty)
{
aNewItem.PromoPrice = 0;
}
// Save this for later so that we know we've added a regular item
else
{
aNewItem.PromoPrice = Convert.ToDecimal(aNewItem.Sell);
}
Reward.StockItemsTaken.Add(aNewItem);
請理解_references_的概念。 –
如果您已經在列表中有相同的項目,它仍然會添加新項目,並且不會修改任何內容。它會修改的唯一原因是如果你在某個地方告訴它。 –
請顯示'StaticLists.GetStockMultibuyForBarcode(sBarcode)'方法代碼 –