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

SilverSun

Client
Joined
Oct 31, 2013
Messages
172
Reaction score
24
Points
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;
 

Radzhab

Client
Joined
May 23, 2014
Messages
1,500
Reaction score
1,268
Points
113
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;
 
Last edited:

SilverSun

Client
Joined
Oct 31, 2013
Messages
172
Reaction score
24
Points
18
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;
Спасибо! Все работает.
 

Users Who Are Viewing This Thread (Total: 1, Members: 0, Guests: 1)