I'm having a List<string>
like:
List<String> list = new List<String>{"6","1","2","4","6","5","1"};
I need to get the duplicate items in the list into a new list. Now I'm using a nested for
loop to do this.
The resulting list
will contain {"6","1"}
.
Is there any idea to do this using LINQ or lambda expressions?
Here's another option:
I know it's not the answer to the original question, but you may find yourself here with this problem.
If you want all of the duplicate items in your results, the following works.
In my situation I need all duplicates so that I can mark them in the UI as being errors.
I was trying to solve the same with a list of objects and was having issues because I was trying to repack the list of groups into the original list. So I came up with looping through the groups to repack the original List with items that have duplicates.