Note that there are some explanatory texts on larger screens.

plurals
  1. POHow duplicate an object in a list and update property of duplicated objects?
    text
    copied!<p>What would be the best way to duplicate an object placed in a list of items and change a property of duplicated objects ?</p> <p>I thought proceed in the following manner: - get object in the list by "ref" + "article" - Cloned the found object as many times as desired (n times) - Remove the object found - Add the clones in the list</p> <p>What do you think?</p> <p>A concrete example:</p> <pre><code>Private List&lt;Product&gt; listProduct; listProduct= new List&lt;Product&gt;(); 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); </code></pre> <p>desired method:</p> <pre><code>public void updateProductsList(List&lt;Product&gt; paramListProducts,Produit objProductToUpdate, int32 nbrDuplication, int32 newQuantity){ ... } </code></pre> <p>Calling method example:</p> <pre><code> updateProductsList(listProducts,objProduct_1,2,15); </code></pre> <p>Waiting result:</p> <p>Replace follow object :</p> <pre><code>ref = "001"; article = "G900"; quantite = 30; </code></pre> <p>By:</p> <pre><code>ref = "001"; article = "G900"; quantite = 15; ref = "001"; article = "G900"; quantite = 15; </code></pre> <p>The Algorithm is correct? Would you have an idea of the method implementation "updateProductsList"</p> <p>Thank you in advance for your help.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload