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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:03:34+00:00 2026-05-22T02:03:34+00:00

I simply want to remove duplicates from two lists and combine them into one

  • 0

I simply want to remove duplicates from two lists and combine them into one list. I also need to be able to define what a duplicate is. I define a duplicate by the ColumnIndex property, if they are the same, they are duplicates. Here is the approach I took:

I found a nifty example of how to write inline comparers for the random occassions where you need em only once in a code segment.

public class InlineComparer<T> : IEqualityComparer<T>
{
    private readonly Func<T, T, bool> getEquals;
    private readonly Func<T, int> getHashCode;

    public InlineComparer(Func<T, T, bool> equals, Func<T, int> hashCode)
    {
        getEquals = equals;
        getHashCode = hashCode;
    }

    public bool Equals(T x, T y)
    {
        return getEquals(x, y);
    }

    public int GetHashCode(T obj)
    {
        return getHashCode(obj);
    }
}

Then I just have my two lists, and attempt a union on them with the comparer.

            var formatIssues = issues.Where(i => i.IsFormatError == true);
            var groupIssues = issues.Where(i => i.IsGroupError == true);

            var dupComparer = new InlineComparer<Issue>((i1, i2) => i1.ColumnInfo.ColumnIndex == i2.ColumnInfo.ColumnIndex, 
            i => i.ColumnInfo.ColumnIndex);

            var filteredIssues = groupIssues.Union(formatIssues, dupComparer);

The result set however is null.

Where am I going astray?
I have already confirmed that the two lists have columns with equal ColumnIndex properties.

  • 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-22T02:03:35+00:00Added an answer on May 22, 2026 at 2:03 am

    I’ve just run your code on a test set…. and it works!

        public class InlineComparer<T> : IEqualityComparer<T>
        {
            private readonly Func<T, T, bool> getEquals;
            private readonly Func<T, int> getHashCode;
    
            public InlineComparer(Func<T, T, bool> equals, Func<T, int> hashCode)
            {
                getEquals = equals;
                getHashCode = hashCode;
            }
    
            public bool Equals(T x, T y)
            {
                return getEquals(x, y);
            }
    
            public int GetHashCode(T obj)
            {
                return getHashCode(obj);
            }
        }
    
        class TestClass
        {
            public string S { get; set; }
        }
    
        [TestMethod]
        public void testThis()
        {
            var l1 = new List<TestClass>()
                         {
                             new TestClass() {S = "one"},
                             new TestClass() {S = "two"},
                         };
            var l2 = new List<TestClass>()
                         {
                             new TestClass() {S = "three"},
                             new TestClass() {S = "two"},
                         };
    
            var dupComparer = new InlineComparer<TestClass>((i1, i2) => i1.S == i2.S, i => i.S.GetHashCode());
    
            var unionList = l1.Union(l2, dupComparer);
    
            Assert.AreEqual(3, unionList);
        }
    

    So… maybe go back and check your test data – or run it with some other test data?

    After all – for a Union to be empty – that suggests that both your input lists are also empty?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array in PHP and I want to remove duplicates. I simply
I have a highchart and I simply want to remove a bar from it.
I simply want to call a swing action from my own popup menu. But
I simply want to fill-up cells in my spreadsheet from a VBA function. By
I simply want to change a variable of an object from another class. I
Hey guys I have an assigned array from mysql results and I simply want
I want to remove a UILabel from the UIView dynamically. There are some branching
I have made my own single chained/linked list. Now, if I want to delete/remove
I want to simply retrieve a single record from a database in a classic
Say B and C are derived from A . I want to be able

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.