linq delegate function checking from objects
- by Philip
I am trying to find the list of objects which can be replaced.
Class Letter{
int ID;
string Name;
string AdvCode;
int isDeleted;
}
Class Replacers{
int ID;
string MainAdvCode;
string ReplacesAdvCode;
}
example data:
Replacers
0 455 400
1 955 400
2 955 455
such that if a Letter has and Advcode of 455 and another has a code of 400 the 400 gets marked for deletion. And then if another Letter has a 955 then the 455 gets marked for deletion and the 400 (which is already marked) is marked for deletion.
The problem is with my current code the 400 and 455 is marking itself for deletion?!?!?
Public class Main{
List<Letter> Letters;
List<Replacers> replaces;
//select the ones to replace the replacements aka the little guys
//check if the replacements replacer exists if yes mark deleted
var filterMethodReplacements = new Func<Letter, bool>(IsAdvInReplacements);//Working
var filterMethodReplacers = new Func<Letter, bool>(IsAdvInReplacers);//NOT WORKING????
var resReplacements=letters.Where(filterMethodReplacements);//working
foreach (Letter letter in resReplacements)
{
//select the Replacers aka the ones that contain the little guys
var resReplacers = letters.Where(filterMethodReplacers);
if (resReplacers != null)
letter.isDeleted = 1;
}
}
}
private bool IsAdvInReplacements(Letter letter)
{
return (from a in Replacables where a.ReplaceAdvCode == letter.AdvCode select a).Any();
}
private bool IsAdvInReplacers(Letter letter)
{
//??????????????????????????????
return (from a in Replacables where a.MainAdvCode == letter.AdvCode select a).Any();
}
}