I have a List of myClass
objects (some elements are added before)
List<myClass> myClassList1;
Then I copy some of the elements in this list into another list
List<myClass> myClassList2 = new List<myClass>();
foreach (myClass obj in myClassList1)
{
myClassList2.Add(obj);
}
This list is now sorted
myClassList2.sort();
And then I want to modify the first element in this sorted list
myClassList2[0].id++;
Problem: in the myClassList2
this element is modified, but not in myClassList1
.
I thought adding myClass
objects to a list will add a reference to this object, so i can modify it in the list (this was the actual plan).