複製放置在項目列表中的對象並更改重複對象的屬性的最佳方法是什麼?如何複製列表中的對象並更新重複對象的屬性?
我想繼續通過以下方式: - 根據需要(n次)克隆找到對象多次 - - 由「裁判」 +「文章」 獲取列表對象中刪除對象中找到 - 添加列表中的克隆
您認爲如何?
一個具體的例子:
Private List<Product> listProduct;
listProduct= new List<Product>();
Product objProduit_1 = new Produit;
objProduct_1.ref = "001";
objProduct_1.article = "G900";
objProduct_1.quantity = 30;
listProducts.Add(objProduct_1);
ProductobjProduit_2 = new Product;
objProduct_2.ref = "002";
objProduct_2.article = "G900";
objProduct_2.quantity = 35;
listProduits.Add(objProduct_2);
期望的方法:
public void updateProductsList(List<Product> paramListProducts,Produit objProductToUpdate, int32 nbrDuplication, int32 newQuantity){
...
}
調用方法例如:
updateProductsList(listProducts,objProduct_1,2,15);
等待結果:
替換跟隨對象:
ref = "001";
article = "G900";
quantite = 30;
通過:
ref = "001";
article = "G900";
quantite = 15;
ref = "001";
article = "G900";
quantite = 15;
的算法是正確的?你有一個想法的方法實施「updateProductsList」
謝謝您的幫助。
這是C#,對不起!我已經刪除了java標誌。 – TimeIsNear 2010-06-06 14:08:33