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 8357205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:24:29+00:00 2026-06-09T10:24:29+00:00

I am having a basic issue here with linq . Though this can be

  • 0

I am having a basic issue here with linq . Though this can be solved with repeated loops . I am trying to know how can this be done in linq .

I have two lists .

List<string> a  = new List<string>{"a","b","c","d","e","f"};
List<string> b = new List<string> { "a", "b", "c", "x", "y", "z" };

I want to compare with list a and whichever element in b is found in a . I want to remove that element from b . In other words I want to remove {“a”,”b”,”c”} from b based on comparison from list a and want to contain only {“x”,”y”,”z”} in list b . Is there a single statement linq to solve this ?

  • 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-06-09T10:24:30+00:00Added an answer on June 9, 2026 at 10:24 am

    (I’m sure this is a duplicate of another post just a few days ago, but I can’t find it…)

    If you need a modification in place, you can use List<T>.RemoveAll:

    b.RemoveAll(x => a.Contains(x));
    

    Or more efficiently (if the lists are large):

    HashSet<string> set = new HashSet<string>(a);
    b.RemoveAll(set.Contains);
    

    Note that modifying a collection in place isn’t idiomatic in LINQ, which is why the above uses the .NET 2 list-specific method.

    Or if you’re happy to change b to refer to a new list instead, then you can use LINQ:

    b = b.Except(a).ToList();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a basic shopping cart, having an issue with the product
I have a pretty basic assignment, but am having an issue making my main
I'm having an issue with a game that I'm trying to make. Here is
I'm having this very odd issue while trying to serialize a class for logging
I'm having a strange issue with my AdvancedDataGrid. I have a pretty basic (no
I feel like this is really basic, but I'm having trouble with this issue.
I think I'm having a really basic problem here but I can't seem to
Sorry for the many posts here regarding this issue but i am having a
I'm having a linking issue with a basic C++ program. No, I'm not including
I'm having an issue while developing a basic Rails application. I've implemented Twitter Bootstrap

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.