Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to find duplicates in a List<T> quickly, and update the original collection
    primarykey
    data
    text
    <p>Let me start by saying I've read these questions: <a href="https://stackoverflow.com/questions/223400/checking-for-duplicates-in-a-complex-object-using-linq-or-lamda-expression">1</a> &amp; <a href="https://stackoverflow.com/questions/454601/how-to-count-duplicates-in-list-with-linq">2</a>, 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.</p> <p>I know I can't update the collection the query returns as it's not a view, it's an anonymous type <code>IEnumerable&lt;T&gt;</code>.</p> <p>I want to be able to find duplicates in my list, and mark a property I've created called <code>State</code> which is used later in the application.</p> <p>Has anyone ran into this problem and can you point me in the right direction?</p> <p>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.</p> <p>EDIT:</p> <p>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</p> <p>I have an overloaded Equals() method on the base class which compares these fields.</p> <p>The only time I skip an object in my <code>MarkDuplicates()</code> method is if the objects state is <code>UNKNOWN</code> or <code>ERROR</code>, otherwise, I test it.</p> <p>Let me know if you need more details.</p> <p>Thanks again!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload