The actual content of this method isn't important, as the question is specific to the language itself I guess. So here it goes.
Here is my method snippet:
private CellValidation.CellValidationResult Validate<B, I>(CellValidation cellToValidate, IList<B> baseListToValidateAgainst, IList<I> importListToValidateAgainst, string invalidMessage, DDSFieldEnum fieldEnum) where I : Entities.DDS.DDSEntityFieldBase where B : Entities.DDS.
//Remove all dashes and /'s for a more realistic mapping check. We don't want the mapping to fail just because the imports - may be different. Also, create local variables of the list as don't want to modify the actual db.
cellToValidate.Value = cellToValidate.Value.Replace("-", " ").Trim().ToLower();
// IList<B> baseList;
var baseList = baseListToValidateAgainst;
baseList.Select(x => { x.Value = x.Value.Replace("-", " ").Trim().ToLower(); return x; }).
...
So I clearly set local baseList variable to equal the parameter passed in, then I modify the baseList variable.
However, this seems to modify the parameter baseListToValidateAgainst and not only the local variable baseList. Why is that?
var baseList = baseListToValidatecopies reference to the same collection, it does not copy the collection itself.