How to identify the duplicates in a list (not deleting them) ?

Aronax

Client
Регистрация
29.01.2015
Сообщения
201
Благодарностей
59
Баллы
28
How can I identify the duplicates in a list?
I don't want to remove the duplicates, I want to identify and save them in a different list.

Also, is there any easy way (like a C# code) of getting the number of times each of these duplicates appear in the list (without putting them in a database and using the database operations for this)?

Thanks guys!
 

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 764
Благодарностей
2 407
Баллы
113
C#:
var rand = new Random();
var list1 = project.Lists["list1"].ToList(); // list one

// del next line
for(int i=0; i<100; i++) list1.Add(string.Format("demo: {0}",rand.Next(10))); // add demo data

var list2 = project.Lists["list2"]; // list result

var items = new HashSet<string>(list1);

foreach (string item in items){
    list2.Add(string.Join("|", new[]{item, list1.Where(x=> x==item).Count().ToString()}));
}
97297
 
  • Спасибо
Реакции: myndeswx и Aronax

Aronax

Client
Регистрация
29.01.2015
Сообщения
201
Благодарностей
59
Баллы
28

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)