linq - How to find duplicates in a List<T> quickly, and update the original collection -


Let me start by saying that I have read these questions: & amp; , And I understand that I can write the code to find duplicates in my list, but my problem is that I want to update the original list and not just duplicate queries and prints.

I know that I can not update the returns to the collection because this is not the view, it is an anonymous type IEnumerable & lt; T & gt; .

I find duplicate in my list and a property I am called state which is later used in the application.

Has anyone participated in this problem and can you tell me in the right direction?

The ATM I am using is a bubble sort type loop, which is the item to go through the item item and compare the key areas. Obviously this is not the fastest way.

Edit:

To consider "duplicate" an item in the list, there are three fields that must match. We call them Field 1, Field 2, and Field 3

I have a base class which is equal to these areas.

Only once when I leave an object, my Mark Duplicate () method is if the objects state UNKNOWN or error Otherwise, I test it.

Let me know that you need more details.

Thanks again!

I think the easiest way is to start by writing an extension method that finds duplicates in the list of objects. . Since you use objects. Aqual () They can be compared in the most common collections.

Public Fixed IEnumerable & lt; T & gt; FindDuplicates & lt; T & gt; (This is IEnumerable & lt; T & gt; enumerable) {var hashase = new hashset & lt; T & gt; (); Foreign currency (different types in enumerable) (if (! Hashasset.ed (CR)) {yield returns;}}}

Now it should be easy to update your archive for duplicates For example

  list & lt; SomeType & gt; list = GetTheList (); list .FindDuplicates () .toList (). First (x => x.State = " DUPLICATE ");  

If you already have the ForEach Extentsion method defined in your code, you can avoid the .oList.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -