Possible Duplicate:
Remove duplicates from array
I have a list of items. I want to select all the items without repetition. How to do that in C#?
Possible Duplicate:
Remove duplicates from array
I have a list of items. I want to select all the items without repetition. How to do that in C#?
You're looking for the aptly-named Distinct()
method.
You may need to write an IEqualityComparer<T>
.
I suppose you mean you want to remove duplicates. Use Distinct
int[] ints = new int[] { 1, 2, 3, 4, 5, 4, 3, 2 };
var uniqueInts = ints.Distinct();
Console.WriteLine(string.Join(", ", uniqueInts));