Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 831959
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:17:16+00:00 2026-05-15T04:17:16+00:00

I am trying to find the list of objects which can be replaced. Class

  • 0

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();
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T04:17:16+00:00Added an answer on May 15, 2026 at 4:17 am

    See below, solution was to group by name and then iterate over the replacers.

        public class Letter
        {
            public int ID;
            public string Name;
            public string AdvCode;
            public string Type;
            public Boolean isDeleted;
    
            public override string ToString()
            {
                return this.Name + "[" + this.ID + "]" + ":" + this.Type + " AdvCode=" + AdvCode + " Deleted: " +  this.isDeleted.ToString();
            }
        }
    
        public class Replacers
        {
            public int ID;
            public string MainAdvCode;
            public string ReplacesAdvCode;
        }
    
    class Program
    {
    
    static void Main(string[] args)
        {
            List<Letter> letters = GetLetters();
            List<Replacers> replacables = GetReplacers();
    
    
    
            foreach (IGrouping<string, Letter> g in letters.GroupBy(x => x.Name))
            {
                List<Letter> byName = g.ToList();
    
    
                foreach (Replacers r in replacables)
                {
                    if (byName.Any(x => x.AdvCode == r.MainAdvCode) && byName.Any(x=>x.AdvCode==r.ReplacesAdvCode))
                    {
                        //If we contain the code to replace...
                        foreach (Letter letter in byName.Where(x=>x.AdvCode==r.ReplacesAdvCode)){
                            letter.isDeleted = true;
                        }
                    }
                }
            }
    
            Console.WriteLine("Result");
            foreach (Letter l in letters.Where(x=>x.isDeleted))
            {
                Console.WriteLine(l.ToString());
            }
            Console.WriteLine("Press key to close");
            Console.ReadKey();
    
      }
    
        public static List<Letter> GetLetters()
        {
            List<Letter> letters = new List<Letter>(){
                new Letter(){
                    Name = "LettersA",
                    ID = 0,
                    AdvCode="455",
                    Type="pack",
                    isDeleted = false
                },
                new Letter(){
                    Name = "LettersA",
                    Type="addon",
                    ID = 1,
                    AdvCode="400",
                    isDeleted = false
                },
                  new Letter(){
                    Name = "LettersB",
                    ID = 0,
                    AdvCode="955",
                    Type="big",
                    isDeleted = false
                },
                new Letter(){
                    Name = "LettersB",
                    Type="pack",
                    ID = 1,
                    AdvCode="455",
                    isDeleted = false
                },
                  new Letter(){
                    Name = "LettersC",
                    ID = 0,
                    AdvCode="400",
                    Type="addon",
                    isDeleted = false
                },
                new Letter(){
                    Name = "LettersC",
                    Type="big",
                    ID = 1,
                    AdvCode="955",
                    isDeleted = false
                },
                 new Letter(){
                    Name = "LettersC",
                    Type="pack",
                    ID = 2,
                    AdvCode="455",
                    isDeleted = false
                },
                  new Letter(){
                    Name = "LettersD",
                    ID = 0,
                    AdvCode="455",
                    Type="pack",
                    isDeleted = false
                },
                new Letter(){
                    Name = "LettersD",
                    Type="none",
                    ID = 1,
                    AdvCode="019",
                    isDeleted = false
                },
            };
    
            return letters;
    
        }
    
        public static List<Replacers> GetReplacers()
        {
            return new List<Replacers>(){
                new Replacers(){
                    ID = 0,
                    MainAdvCode = "455",
                    ReplacesAdvCode = "400"
                },
                new Replacers(){
                    ID = 1,
                    MainAdvCode = "955",
                    ReplacesAdvCode = "400"
                },
                new Replacers(){
                    ID = 2,
                    MainAdvCode = "955",
                    ReplacesAdvCode = "455"
                },
            };
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a customers List(of String) on which I am trying to find the
I'm trying to find a way to make a list of parent object with
I am trying to find a list of what ISBNs are in use. I
I am trying to find a list of Microsoft OS Descriptors for USB. The
I am trying to find a full list of Selenium RC browser launchers. So
I'm trying to find the average of a list of floats. let avg l
I'm trying to find out the index number of the last list item but
I'm currently trying to create a class which implements IEnumerable<T> in order to construct
I have a swing application which stores a list of objects. When the users
So I am trying to retrieve a list of blog entries, which has a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.