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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:11:44+00:00 2026-05-28T13:11:44+00:00

I use LINQ on a Dictionary<string, IList<ID>> like this: var searchCategories = new List

  • 0

I use LINQ on a Dictionary<string, IList<ID>> like this:

var searchCategories = new List {"A", "B", "C"};
Result = CategoryMapper.Mapping.Where(
         x => searchCategories.Contains(x.Key)).
         Select(x => new Tuple<string, IList<ID>>(x.Key, x.Value)).ToList();

This returns all ids that are either in Category A, B or C. However what I would like to do is retrieve ids that are in Category A, B and C.

I’m having difficulties figuring out how to do this with Linq.

UPDATE

I’m sorry but I should have added some more information in my initial post. The lists in my dictionary look somewhat like this (I only use numbers here to make it simple):

A : {1, 2, 3}
B : {1,3}
C : {3}

So what I would like as a result of my query would be ‘3’ in this case because it is the only number that has all categories.

  • 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-28T13:11:45+00:00Added an answer on May 28, 2026 at 1:11 pm

    Looks like you’re just taking the intersection of all the lists. That should be simple to obtain.

    var searchCategories = new HashSet<string> { "A", "B", "C" };
    var result = CategoryMapper.Mapping
        .Where(map => searchCategories.Contains(map.Key))
        .Select(map => map.Value as IEnumerable<ID>)
        .Aggregate((acc, cur) => acc.Intersect(cur));
    

    If your ID type doesn’t implement the IEquatable<ID> interface, then you may need to provide an equality comparer (that I assume you have) to perform the comparisons.

     ....Aggregate((acc, cur) => acc.Intersect(cur, new YourIdEqualityComparer()));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Dictionary in C#: Dictionary<string, List<string>> How can I use Linq to
I can't use TryGetValue() from dictionary in linq expression with anonymous type. Dictionary<string, string>
I am using LINQ to query a generic dictionary and then use the result
Dictionary<string,string> items = new Dictionary<string,string>(); IEnumerable<string> textvalues = from c in......//using linQ to query
I am trying to use LINQ to retrieve some data from a dictionary. var
I'm trying to use LINQ to create a new dictionary from an existing one,
I would like to use Linq to Xml to get a single XElement from
I would like to use Linq to query a bus schedule in my project,
I have two complex dictionaries in the form Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>> So as
LinQ contains the method Cast which casts each entry in the list to type

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.