Javier

Javier

  • NA
  • 7
  • 7.3k

How to copy one element of a Generic Collection?

Feb 6 2011 10:50 AM

I need to copy one element of a generic collection and add it to the list. Something similar to this:
 

private List<CalculationResult> cantileverResults = new List<CalculationResult>();
cantileverResults.Add(cantileverResults[previousIndex]);
The problem with this solution is that when I modify the new element, the previousIndex element changes as well. I believe this is because they are reference-type, not value-type. How can I just copy (clone?) the information from one element to another without affecting each other any further?

Answers (5)