c# - How to manage two list object reference that are pointing to same collection? -


at run time program assign 2 properties same collection. took 2 properties if changing collection done 1 property , second hold same collection is. behind scene both pointing same, can not hold collection no changes 1 property. require wok ok , cancel button if no changes 1 prperty take care or this, , if changes done other property wil take care of this.

how can manage this?

like this

private void btnok_click(object sender, eventargs e)         {             program.currorder.orderitems[program.editindex].appliedcustomization = lstbtn;//objfreecusatomization.allapplieditems;             this.dialogresult = system.windows.forms.dialogresult.ok;         }          private void btncancel_click(object sender, eventargs e)         {             program.currorder.orderitems[program.editindex].appliedcustomization = actualbtnlist;             this.dialogresult = dialogresult.cancel;         } 

these 2 properties being assined other program

public list<btnobject> lstbtn;         public list<btnobject> actualbtnlist { get; set; } 

from other program how set

  frmprepare.actualbtnlist = frmprepare.lstbtn = program.currorder.orderitems[curridx].appliedcustomization; 

there tow options either when creating actual list, items original list , fill new list, suppose in loop(transferring value of properties 1 one), can use reflection same.

other if object serialize first serialize original list , deserialize copies value , not reference.

for second option code go this:

using (var memorystream = new memorystream()) {    var binaryformatter = new binaryformatter();    binaryformatter.serialize(memorystream, <your original list object>);    memorystream.position = 0;     <you actual list object> =  binaryformatter.deserialize(memorystream); } 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -