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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:57:56+00:00 2026-05-11T08:57:56+00:00

I am trying to get the subset of items in dataA that are in

  • 0

I am trying to get the subset of items in dataA that are in dataB, and have different values of property c. The properties a and b can be used as an index, so I have tried to filter out only the useful pairs then check to see if they have a different c value.

This is the linq expression I came up with, and it does work, but It seems like there has to be a better/faster way of finding this subset.

var itemsInBoth = from item in dataA                   from item2 in dataB                   where item.a == item2.a && item.b == item2.b                       select new                       {                           first= item,                           second = item2                       }; var haveDifferentC = from item in itemsInBoth                       where item.first.c != item.second.c                      select item.first; 
  • 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. 2026-05-11T08:57:56+00:00Added an answer on May 11, 2026 at 8:57 am

    Faster? What you have there is O(n^2). Each item in the first list will fully iterate the items in the second list. You need to remove the redundant iteration in that join. One way to do that is to use another structure to do O(1) lookups for matchs.

    Here’s some untested (unchecked) code:

    var dictionaryA = dataA   .GroupBy(item => new {a = item.a, b = item.b})   .ToDictionary(g => g.Key, g => g.ToList());  var dictionaryB = dataB   .GroupBy(item => new {a = item.a, b = item.b})   .ToDictionary(g => g.Key, g => g.ToList());  var results = dictionaryA   .Where(g1 => dictionaryB.ContainsKey(g1.Key))   .Select(g1 => new {g1 = g1, g2 = dictionaryB[g1.Key]})   .SelectMany(pair =>     pair.g1.SelectMany(item1 =>       pair.g2       .Where(item2 => item2.c != item1.c)       .Select(item2 => new {item1, item2})     )   ); 

    Here’s a simplified version if a,b pairs are unique in each list.

    var dictionaryA = dataA   .ToDictionary(item => new {a = item.a, b = item.b}, item => item);  var dictionaryB = dataB   .ToDictionary(item => new {a = item.a, b = item.b}, item => item);  var results = dictionaryA   .Where(e1 => dictionaryB.ContainsKey(e1.Key))   .Select(e1 => new {i1 = e1.Value, i2 = dictionaryB[e1.Key]})   .Where(pair => pair.i1.c != pair.i2.c); 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 66k
  • Answers 66k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer There is no generic best way. But there is a… May 11, 2026 at 11:34 am
  • added an answer :help sub-replace-expression You can construct a replace expression like: :s@… May 11, 2026 at 11:33 am
  • added an answer First, you need to use remove() instead of erase() (the… May 11, 2026 at 11:33 am

Related Questions

I am trying to get the Edit with Vim context menu to open files
I am trying to get the DB2 data provider from a 32-bit .Net application
I am trying to get the yasnippet and pabbrev packages working together with emacs,
I am trying to get the DataGridView to render the insert new row row
I am trying to get the Azure SDK up and running on my dev
I am trying to get the path to a folder in my website root
I am trying to find a way to get the source code for (user
I am trying to work out how to get the value of table cell
I am working on my website, and I am trying to get the url
Question I am trying to dynamically get the default for a type that is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.