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
LettersA
0 pack 455
1 addon 400
LettersB
0 big 955
1 pack 455
LettersC
0 addon 400
1 big 955
2 pack 455
LettersD
0 pack 455
1 none 019
solution:
LetterA 1 isDeleted
LeterB 1 isDeleted
LetterC 0 and 2 isDeleted
LetterD ---
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();
}
}