I have a created a custom type in C# called InfInt
. Each InfInt
object has its own list of ints declared as follows:
public List<int> Numbers = new List<int>();
Then, elsewhere in the program, I have a loop where a temporary InfInt
object is needed. At the end of the loop, when temporary InfInt
has been filled with information, I want to add this object to a list of InfInt
objects which is declared like this: var ListOfLists = new List<InfInt>();
. The following code adds the temporary InfInt
object to ListOfLists
list of InfInt
objects:
ListOfLists.Add(Temp);
Then, right when a new iteration should start, I obviously need to clear the data in the temporary InfInt
object. I use the following code for this:
Temp.Numbers.Clear();
Now comes the problem. When I clear the Temp
's data, it is cleared in ListOfLists
too... How should I fix this?