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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:56:44+00:00 2026-05-24T20:56:44+00:00

I think this would take O(A x B) time to execute. (where A is

  • 0

I think this would take O(A x B) time to execute.

(where A is the size of collectionA and B is the size of collectionB)

Am I correct?

IEnumerable<A> GetMatches(IEnumerable<A> collectionA, IEnumerable<B> collectionB)
{
    foreach (A a in collectionA)
        foreach (B b in collectionB)
            if (a.Value == b.Value)
                yield return a;
}

Is there a faster way to execute this query? (maybe using LINQ?)

  • 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-24T20:56:45+00:00Added an answer on May 24, 2026 at 8:56 pm

    Enumerable.Intersect will not, unfortunately, work as you’re comparing against two separate types (A and B).

    This will require a bit of handling separately to get an Intersect call that will work.

    You could do this in stages:

    IEnumerable<A> GetMatches(IEnumerable<A> collectionA, IEnumerable<B> collectionB)
         where A : ISomeConstraintWithValueProperty
         where B : ISomeOtherConstraintWithSameValueProperty
    {
        // Get distinct values in A
        var values = new HashSet<TypeOfValue>(collectionB.Select(b => b.Value));
    
        return collectionA.Where(a => values.Contains(a.Value));
    }
    

    Note that this will return duplicates if collectionB contains duplicates (but not collectionA), so it will have slightly different results than your looping code.

    If you want unique matches (only one returned), you could change the last line to:

    return collectionA.Where(a => values.Contains(a.Value)).Distinct();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

you would think this would be obvious, but searching through documentation, SAP forums, Googling,
How can I force validation when user clicks button? One would think this should
How would I do this? I think this has something to do with editing
I would like to do the following but I don't think this will work:
Okay at first I thought this would be pretty straightforward. But I can't think
See what you think of this line of code: if ([pickerViewController.picker.bvc.currentResolve.name isEqualToString:message]) ... Would
What is the function of the namespace here? I would think in this simple
This is something that I think would be very useful. Basically, I'd like there
This should be pretty straightforward I would think. I have this string: [quote=Joe Johnson|1]Hi![/quote]
Sorry if this is duplicate,I would think it would be but couldn't find anything.

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.