I have a loop:
List<A> list = new List<A>();
A obj = new A();
for (int i = 0; i < 10; ++i)
{
obj.num = i; // Assigns the current i to the num attribute inside obj
list.Add(obj);
}
However, in this case, whenever I modify obj
, the previous instances of obj
already added into the list
will be modified. How do I write the code such that whatever that is added into the list has no more reference to the current value of obj
?