I have a collection like this:
List<string> names = new List<string>
{
"One",
"Two"
"One",
"Three",
"One",
"One"
};
I want to remove those extra "Ones", leaving only the first "One" in. The code below doesn't work somehow.
foreach (var item in names)
{
if (names.Contains(item) && names.Count(x => x == item) > 1)
{
names.Remove(item);
}
}
What are other, cleaner options? :)
Thank you in advance.