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

  • Home
  • SEARCH
  • 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 4001426
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:54:12+00:00 2026-05-20T07:54:12+00:00

I have two lists of the same type. That type does not have an

  • 0

I have two lists of the same type. That type does not have an identifier or any other guaranteed way to programatically distinguish.

  • List A: {1, 2, 2, 3, 5, 8, 8, 8}
  • List B: {1, 3, 5, 8}

I want the items from A that are not in B.

  • Desired Result: {2, 2, 8, 8}

If the types had identifiers, I could use a statement like the following…

var result = listA
      .Where(a => listB.Where(b => b.Id == a.Id).Count() == 0)
      .ToList();

So far, the only way I can do this is with a loop where I add each item the number of times it doesn’t appear in the original list.

foreach (var val in listB.Select(b => b.val).Distinct())
{
  var countA = listA.Where(a => a.val == val).Count();
  var countB = listB.Where(b => b.val == val).Count();
  var item = listA.Where(a => a.val == val).FirstOrDefault();

  for (int i=0; i<countA-countB; i++)
    result.Add(item);
}

Is there a cleaner way to achieve this?

EDIT:
Here is a simplified version of the object in the lists. It’s coming from a Web service that’s hitting another system.

public class myObject
{
  public DateTime SomeDate { get; set; }
  public decimal SomeNumber; { get; set; }
  public bool IsSomething { get; set; }
  public string SomeString { get; set; }
}

The data I am receiving has the same values for SomeDate/SomeString and repeated values for SomeNumber and IsSomething. Two objects might have equal properties, but I need to treat them as distinct objects.

  • 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-20T07:54:13+00:00Added an answer on May 20, 2026 at 7:54 am

    try this:

    var listA = new List<Int32> {1, 2, 2, 3, 5, 8, 8, 8};
    var listB = new List<Int32> {1, 3, 5, 8};
    var listResult = new List<Int32>(listA);
    
    foreach(var itemB in listB)
    {
        listResult.Remove(itemB);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two C# classes that have many of the same properties (by name
I have two lists based on the same class. I would like one list
I have two lists of custom objects and want to update a field for
I have two lists of objects. Each list is already sorted by a property
I have two lists, each on different tabs (sub-sites) of the site. I would
Say I have two lists: var list1 = new int[] {1, 2, 3}; var
I have two classes: Media and Container. I have two lists List<Media> and List<Container>
I have two unsorted lists and I need to produce another list which is
I have two Sharepoint lists: - Assignments - Activities The activities list has a
I have a form that is displayed, not by ShowDialog, but by setting its

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.