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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T12:24:53+00:00 2026-06-06T12:24:53+00:00

With the following object hierarchy, I need to confirm whether or not all string

  • 0

With the following object hierarchy, I need to confirm whether or not all string Id values are present in Inventories of each SearchResult e.g.

Given a string[] list = { "123", "234", "345" } confirm all list values are present at least once in the array of Inventory elements. I’m curious if I can clean this up using one LINQ statement.

SearchResult
--
Inventory[] Inventories

Inventory
--
String Id

Right now, I’m splitting list e.g.

list.Split(').ToDictionary(i => i.ToString(), i => false)

And iterating the dictionary, testing each Inventory. Then, I create a new List<SearchResult> and add items if there are no false values left in the dictionary. This feels clunky.

Code

// instock: IEnumerable<SearchResult>
foreach (var result in instock)
{
    Dictionary<string, bool> ids = list.Split(',').ToDictionary(i => i.ToString(), i => false);
    foreach (var id in ids)
        if (result.Inventory.Any(i => i.Id == id.Key))
            ids[id.Key] = true;

    if (!ids.Any(i => i.Value == false))
        // instockFiltered: List<SearchResult>
        instockFiltered.Add(result);
}
  • 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-06T12:24:56+00:00Added an answer on June 6, 2026 at 12:24 pm

    Here is a bit of code I wrote. The advantage here is that it uses a hash map, so it has theoretically linear complexity.

        public static bool ContainsAll<T>(this IEnumerable<T> superset, IEnumerable<T> subset, IEqualityComparer<T> comparer)
        {
            var set = new HashSet<T>(superset, comparer);
            return set.IsSupersetOf(subset);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following object: public class Product { string Name {get;} int Quantity {get;}
I need some help defining the following object hierarchy/ database relationship in Hibernate From
Given the following assemblage of classes (contrived): public class School { [PrimaryKey] public string
The hierarchy is the following: Parent object is associated with a Child object. I
I have a situation where I need to determine whether or not an inherited
Given the following hierarchy class Content < ActiveRecord::Base end class Page < Content end
Given is the following class hierarchy: Class Diagram http://img535.imageshack.us/img535/4802/personusermanager.jpg Additional info: The Person class
I need to be able to dynamically modify an NSMenu hierarchy each time it
Suppose you have the following object hierarchy: class Vehicle { public: virtual ~Vehicle() {}
I have an object hierarchy similar to the following: interface IVideoStream { } abstract

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.