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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:32:17+00:00 2026-06-14T15:32:17+00:00

I have 2 lists with some data in: List1.Add(new Filter { Name = Foo,

  • 0

I have 2 lists with some data in:

List1.Add(new Filter { Name = "Foo", Value = "Bar" });
List2.Add(new Filter { Name = "Foo", Value = "Bar" });

I would like to use Linq to return true if List1 contains ALL the values in List2, the example above would obviously return true but this is an example but if I added

List2.Add(new Filter { Name = "Foo1", Value = "Bar1" });

then it should return false.

I started going down the lines of:

var Result = from item1 in List1
             join item2 in List2 on item1.Name equals item2.Name
             new { item1, item2 };

but this would only match on the Name and I’m pretty sure I am going down the wrong route with this.

EDIT: Just to clarify, I don’t want only the VALUE property. Name && Value must match in both lists.

  • 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-14T15:32:18+00:00Added an answer on June 14, 2026 at 3:32 pm

    You can use Except:

    var l1Vals = List1.Select(f => f.Value);
    var l2Vals = List2.Select(f => f.Value);
    var notInL1 = l2Vals.Except(l1Vals);
    if(notInL1.Any())
    {
        // no, not all Values of List2 are in List1
    }
    

    Edit According to your last edit that you want to compare all properties of Filter, the best approach is to create a custom IEqualityComparer<Filter> and use that as argument for this Enumerable.Except overload:

    public class Filter {
        public String Name { get; set; }
        public String Value { get; set; }
    
        public class Comparer : IEqualityComparer<Filter>
        {
            public bool Equals(Filter x, Filter y)
            {
               if(ReferenceEquals(x, y))
                   return true;
               else if(x==null || y==null)
                   return false;
               return x.Name  == y.Name
                   && x.Value == y.Value;
            }
    
            public int GetHashCode(Filter obj)
            {
                unchecked 
                {
                    int hash = 17;
                    hash = hash * 23 + obj.Name.GetHashCode();
                    hash = hash * 23 + obj.Value.GetHashCode();
                    return hash;
                }
            }
        }
    }
    

    Now this works:

    var notInL1 = List2.Except(List1, new Filter.Comparer());
    if (notInL1.Any())
    {
        // no, not all properties of all objects in List2 are same in List1
        // notInL1 contains the set difference
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some financial data gathered at a List[(Int, Double)], like this: val snp
I have some C structures related to a 'list' data structure. They look like
I have got some lists, and I want to filter elements from them. Here's
I have some xml files which contain the source data for populating dropdown lists
I have a list of states, each with some data associated with it, displayed
I am trying to group some data without much luck. I have a list
Say you have a simple class with some storage data structure (list, vector, queue,
I have some lists of numbers: [1, 2, 3, 4, 5] [2, 3, 4,
I have a HAML page that lists some links to delete things that looks
Just some example code here, but I have lists of strings that I want

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.