In my following code, myOriginalList is still getting modified. How do I keep it unchanged?
Thanks for your help.
List<Product> myOriginalList = GetList();
List<Product> customList= new List<Product>();
foreach (var productType in myProductTypeList )
{
var tempList = myOriginalList.ToList();
var result = GetModifiedCustomList(tempList, productType );
customList.AddRange(result);
}
.....
.....
private List<Product> GetModifiedCustomList(List<Product> inplist, string productType)
{
List<Product> tmpList = new List<Product>(inplist);
if (tmpList?.Count > 0)
{
tmpList.ForEach(r => { if (r.ProductType == "NONE") { r.ProductType= productType; } });
}
return tmpList;
}