Well, here is the LINQ approach:
string deduped = string.Join(",", original.Split(',')
.Select(x => x.Trim())
.Distinct());
Please note that I use Trimbecause the source line has a space before each element, but there is no result.
Distinct()it doesn’t actually guarantee that the ordering will be preserved, but the current implementation does this, and it is also the most natural implementation. It’s hard for me to imagine that this will change.
.NET 3.5, .ToArray() Distinct(), .NET 4 string.Join.