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
Since a List
is a reference type, what is passed to the function is a reference to the original list.
See this MSDN article for more information about how parameters are passed in C#.
In order to achieve what you want, you should create a copy of the list in SomeOperationFunction
and return this instead. A simple example:
void List- SomeOperationFunction(List
- target)
{
var newList = new List
- (target);
newList.RemoveAt(3);
return newList; // return copy of list
}
As pointed out by Olivier Jacot-Descombes in the comments to another answer, it is important to bear in mind that
[...] the list still holds references to the same items if the items are of a reference type. So changes to the items themselves will still affect the items in both lists.