c# - How to copy one element of a generic collection -


i need copy 1 element of generic collection , add list. similar this:

private list<calculationresult> cantileverresults = new list<calculationresult>(); cantileverresults.add(cantileverresults[previousindex]); 

the problem solution when modify new element, previousindex element changes well. believe because reference-type, not value-type. how can copy (clone?) information 1 element without affecting each other further?

you need create new object when adding it.

this can done in several ways - helper method takes object of type (calculationresult) , returns new one.

perhaps have constructor overload this.

there many ways achieve such thing - implementing icloneable , having clone method return new object.

for example, if create constructor overload, how use it:

cantileverresults.add(new calculationresult(cantileverresults[previousindex])); 

Comments

Popular posts from this blog

Delphi Wmi Query on a Remote Machine -