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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:04:19+00:00 2026-05-11T15:04:19+00:00

Let me start by saying I’ve read these questions: 1 & 2 , and

  • 0

Let me start by saying I’ve read these questions: 1 & 2, and I understand that I can write the code to find duplicates in my List, but my problem is I want to update the original list not just query and print the duplicates.

I know I can’t update the collection the query returns as it’s not a view, it’s an anonymous type IEnumerable<T>.

I want to be able to find duplicates in my list, and mark a property I’ve created called State which is used later in the application.

Has anyone ran into this problem and can you point me in the right direction?

p.s. The approach I’m using ATM is a bubble sort type loop to go through the list item by item and compare key fields. Obviously this isn’t the fastest method.

EDIT:

In order to consider an item in the list a ‘duplicate’, there are three fields which must match. We’ll call them Field1, Field2, and Field3

I have an overloaded Equals() method on the base class which compares these fields.

The only time I skip an object in my MarkDuplicates() method is if the objects state is UNKNOWN or ERROR, otherwise, I test it.

Let me know if you need more details.

Thanks again!

  • 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-11T15:04:20+00:00Added an answer on May 11, 2026 at 3:04 pm

    I think the easiest way is to start by writing an extension method which find’s duplicates in a list of objects. Since you’re objects use .Equals() they can be compared in most common collections.

    public static IEnumerable<T> FindDuplicates<T>(this IEnumerable<T> enumerable) {   var hashset = new HashSet<T>();   foreach ( var cur in enumerable ) {      if ( !hashset.Add(cur) ) {       yield return cur;     }   } } 

    Now it should be pretty easy to update your collection for duplicates. For instance

    List<SomeType> list = GetTheList(); list   .FindDuplicates()   .ToList()   .ForEach(x => x.State = 'DUPLICATE'); 

    If you already have a ForEach extentsion method defined in your code, you can avoid the .ToList.

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

Sidebar

Related Questions

Let's start by saying that my code works perfectly fine, there is no problem
Let me start by saying that I do not advocate this approach, but I
Let me start out by saying that I'm not a JavaScript developer so this
Let me start by saying that I know that NH doesn't recommend using bulk
Let me start by saying that my understanding of how JNA and Java direct
Let me start by saying that I'm not a power-JavaScript/jQuery programmer, I do very
Let me start by saying I'm a huge fan of the elegance of this
First off, let me start off that I am not a .net developer. The
Before I start with the real question, let me just say that I might
Let me start by saying, I'm no expert in windows file permissions, so maybe

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.