c# - Full copy small List to Container List, not only reference -


i hoping new keyword, not create new object, unique memory references. if this, , after clear "tinylist", biglist cleared.

biglist.add(new biglistobject(tinylist)); 

biglist list , construcotr looks like

public foo(list<smallclass> in)     {         _test = new list<smallclass>();         _test = in;     } 

this works, how can clear tinylist, fill it, , continue adding biglist? whole idea have big list , 1 small adding.. have 2 lists 2 different classes, same. thanks

you can copy references new list:

public foo(list<smallclass> in) {     _test = new list<smallclass>(in); } 

now _test , in point 2 different lists, removing object 1 list not affect other.

however, same references. editing 1 of smallclass instances in list in affect corresponding instance in list _test because references point same instances.

if need copies of smallclass instances you'll need implement copy method (or use object.memberwiseclone)


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -