I have a list that gets filled in with some data from an operation and I am storing it in the memory cache. Now I want another list which contains some sub data from the li
You'll need to make a copy of the list since in your original code what you're doing is just passing around, as you correctly suspected, a reference (someone would call it a pointer).
You could either call the constructor on the new list, passing the original list as parameter:
List- SomeOperationFunction(List
- target)
{
List
- result = new List
- (target);
result.removeat(3);
return result;
}
Or create a MemberWiseClone:
List- SomeOperationFunction(List
- target)
{
List
- result = target.MemberWiseClone();
result.removeat(3);
return result;
}
Also, you are not storing the return of SomeOperationFunction anywhere, so you might want to revise that part as well (you declared the method as void, which should not return anything, but inside it you're returning an object).
You should call the method this way:
List- target = SomeOperationFunction(mainList);
Note: the elements of the list will not be copied (only their reference is copied), so modifying the internal state of the elements will affect both lists.