I have the below code.
I am removing the data in RecoveryRecords variable based on the below conditions if it is not in the ValidClaimControl Numbers.
After executing the line at RecoveryRecords.Remove(s), it is removing from records variable also. I actually need the data from records variable.
I am wondering how i can retain data in records variable?
List<List<Field>> records = new List<List<Field>>();
List<List<Field>> RecoveryRecords = new List<List<Field>>();
//Some Logic here to populate records variable
RecoveryRecords = records;
List<string> validClaimControlNo = new List<string>();
//Some Logic here to populate validClaimControlNo variable
foreach (List<Field> s in RecoveryRecords.ToList())
{
foreach (Field f in s)
{
if (!(validClaimControlNo.Contains(f.Value)))
RecoveryRecords.Remove(s);
}
}
By enumerating the elements into a new List
(much like you do in the foreach loop by saying
RecoveryRecords.ToList())