I have the following sample codes. I don’t like to have lTest being captured and get the same value as lRet. I tried to introduce “List<Test> lTest1 = lTest0;” in the function AddMore2Test. It does not work. What is the proper way to do this?
Thanks!
Codes –
private void Test(){
List<Test> lTest = GetInitTestList();
List<Test> lRet = AddMore2Test(lTest);
}
private List<Test> AddMore2Test (List<Test> lTest0) {
List<Test> lTest1 = lTest0;
return lTest1.Where(…);
}
So at the end of it all you want
lTestto contain an initial set of values, andlRetto contain those initial values, but with a bit of filtering applied? The problem is you are dealing with references, so ultimately everything is pointing at the same list. A quick, simple fix is to just do this:List<Test> lRet = AddMore2Test(lTest.ToList());