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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:16:47+00:00 2026-05-23T07:16:47+00:00

I have two generic lists. Let’s say they are List< A > and List<

  • 0

I have two generic lists. Let’s say they are List< A > and List< B >.

ClassA has a property, which type is List< B >. This property contains B type objects, which are filtered by some other proerties of object A.

So:

class A{
  public int Something1;
  public int Something2;
  public List<B> Something3;
}

class B{
  public int Anything1;
  public int Anything2;
}

I’d like to add all object B as a list to object A (to Property called Something3), where let’s say object A.Something1 == B.Anything1.

My question is: what is the most efficient way of adding List<B> items to List<A> items? Note, there can be hundreds of thousands of objects in both lists.

(VS2010; C#; .Net4)

  • 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-23T07:16:47+00:00Added an answer on May 23, 2026 at 7:16 am

    Group the B‘s on the Anything1 property and put in a dictionary. Then you can loop through the A‘s and efficiently pick out the list of B‘s:

    Dictionary<int, List<B>> beegroups = bees.GroupBy(b => b.Anything1).ToDictionary(g => g.Key, g => g.ToList());
    
    foreach (A a in ayes) {
      List<B> group;
      if (beegroups.TryGetValue(a.Something1, out group)) {
        a.Something3 = group;
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two generic lists of the same type. How do I
I have a generic list which I form from two other lists. The orderby
I have a two generic abstract types: Entity and Association . Let's say Entity
I have two generic list objects, in which one contains ids and ordering, and
I have two generic lists of type T. Both lists contain same type, and
I have two Generic Lists with the same objects Type T within them. For
I have two classes, CheckboxItemsList which extends a generic list, and CheckboxItems , which
I have two threads, a producer thread that places objects into a generic List
I'm having trouble grasping generic methods. I have two classes that are generated (they
I have two EmailAddress generic lists, I wanted a simple way of just getting

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.