I have a class that the constructor requires a class and other things like:
public class SomeClass<T>
{
//global private variables for class
List<T> originalList = new List<T>;
List<T> tempList = new List<T>;
public SomClass(List<T> listParam, string name, ..etc)
{
originalList = listParam;
tempList = listParam;
originalList.removeAt(0); // this also removes an item from tempList.
}
}
I know this is because originalList and tempList have the same reference. How could I make them have diferent references. I use the tempList to filter results and whenever I want to refresh I use the originalList
You could make a copy of
listParam, rather than just assigning its reference:Note that this does not create a copy of each object in the list, but just a copy of the references to those objects.