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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:17:18+00:00 2026-05-23T02:17:18+00:00

I have two Lists of custom objects: List1: Year, Month, ValueA List2: Year, Month,

  • 0

I have two Lists of custom objects:

List1: Year, Month, ValueA
List2: Year, Month, ValueB

I want to get a third List with a merge between the two:

List3: Year, Month, ValueA, ValueB

Is there any elegant way to perform that in LINQ VB.Net?

Example:

List1:
2010 - 6 - 2
2010 - 7 - 5
2010 - 10 - 3

List2:
2010 - 7 - 2
2010 - 8 - 1
2010 - 10 - 2

List3 (result):
2010 - 6 - 2 - 0
2010 - 7 - 5 - 2
2010 - 8 - 0 - 1
2010 - 10 - 3 - 2

Thanks in advance.

Solution
VB.Net translation of the solution :

Dim ListA = From a In List1
    Group Join b In List2
    On a.Year Equals b.Year And a.Month Equals b.Month Into bGroup = Group
    From b In bGroup.DefaultIfEmpty()
    Select a.Year, a.Month, a.Value1, Value2 = If(b Is Nothing, 0, b.Value2)
Dim ListB = From b In List2
    Group Join a In List1
    On b.Year Equals a.Year And b.Month Equals a.Month Into aGroup = Group
    From a In aGroup.DefaultIfEmpty()
    Select b.Year, b.Month, Value1 = If(a Is Nothing, 0, a.Value1), b.Value2
Dim List3 = ListA.Union(ListB)
  • 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-23T02:17:19+00:00Added an answer on May 23, 2026 at 2:17 am

    Sure, you’re looking to perform a Full Outer Join on the data, which doesn’t exist in LINQ, so we fake it with two unioned Left Outer Joins:

    var A = from a in List1
        join b in List2 on new { a.Year, a.Month } equals new { b.Year, b.Month }
            into bgroup
        from b in bgroup.DefaultIfEmpty()
        select new { a.Year, a.Month, a.ValueA, ValueB = (b == null ? 0 : b.ValueB) };
    
    var B = from b in List2
        join a in List1 on new { b.Year, b.Month } equals new { a.Year, a.Month } 
            into agroup
        from a in agroup.DefaultIfEmpty()
        select new { b.Year, b.Month, ValueA = (a == null ? 0 : a.ValueA), b.ValueB };
    
    var List3 = A.Union(B);
    

    Many apologies for the C#, I could not get my VB.Net example to work for the life of me. You need two left outer joins to be unioned to produce the correct answer. None of the code converters I tried worked either.


    The following is VB.Net that LINQPad chokes on, but every example I can find says should be correct:

    Dim A = From a In List1 _
        Group Join b In List2 _
            On New With { a.Year, a.Month } Equals New With { b.Year, b.Month} _
            Into bGroup = Group _
        From b In bGroup.DefaultIfEmpty() _
        Select a.Year, a.Month, a.ValueA, ValueB = If(b Is Nothing, 0, b.ValueB)
    
    Dim B = From b In List2 _
        Group Join a In List1 _
            On New With { b.Year, b.Month } Equals New With { a.Year, a.Month} _
            Into aGroup = Group _
        From a In aGroup.DefaultIfEmpty() _
        Select b.Year, b.Month, ValueA = If(a Is Nothing, 0, a.ValueA), b.ValueB
    
    Dim List3 = A.Union(B)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two lists of custom objects and want to update a field for
I have two lists (list1 and list2) containing references to some objects, where some
I have two lists of objects. Each list is already sorted by a property
We have two lists: a=['1','2','3','4'] b=['2','3','4','5'] How to get a list with elements that
I have a list of custom objects with two properties as identifiers (IDa and
I have a list of custom objects: say Fruits with two string properties Name
I have two lists and I want to select items that are not in
I have two lists which are guaranteed to be the same length. I want
i have two lists: List<comparerobj> list_c = new List<comparerobj>(); List<comparerobj> list_b = new List<comparerobj>();
I have a list with two or more objects of class Agent. Name =

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.