Как удалить дубли в списке с помощью C#

  • Автор темы Автор темы SilverSun
  • Дата начала Дата начала

SilverSun

Client
Регистрация
31.10.2013
Сообщения
172
Реакции
24
Баллы
18
Этот код удаляет пустые строки в файле, что надо сюда дописать что бы он сразу удалял дубли в этом же файле?

// Delete blank lines from file
string path = project.Variables["puth"].Value; // Gets file path from your project variable with name "filePath"
var lines = System.IO.File.ReadAllLines(path).Where(arg => !string.IsNullOrWhiteSpace(arg));
System.IO.File.WriteAllText(path, string.Join(Environment.NewLine, lines));
return 0;
 
C#:
Развернуть Свернуть Копировать
string path = project.Variables["puth"].Value;
var lines = System.IO.File.ReadAllLines(path).ToList().Distinct().ToList();;
System.IO.File.WriteAllText(path, string.Join(Environment.NewLine, lines));
return 0;
 
Последнее редактирование:
C#:
Развернуть Свернуть Копировать
string path = project.Variables["puth"].Value;
var lines = System.IO.File.ReadAllLines(path).ToList().Distinct().ToList();;
System.IO.File.WriteAllText(path, string.Join(Environment.NewLine, lines));
return 0;

Спасибо! Все работает.
 

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