Если у моего значения есть дубликат, я хочу удалить свое значение и дубликат
Вот как это сделать:
1. Create a dictionary in which the key is an item, and the value is an int.
2. Enumerate the items in your collection. For each item:
2.1. If the item is already in the dictionary, get the value, increment it,
and put it back in the dictionary. Otherwise, put the item in the
dictionary with a value of 1.
3. Enumerate the items in your dictionary. For each item:
3.1 Get the corresponding value of the item from the dictionary, and if
it is greater than 1, remove all occurrences of that item from the
collection.
Конечно, по порядкучтобы это работало, ваш 'элемент' должен иметь семантику значения, а не семантику объекта.На практике это означает, что он должен иметь метод Equals (), а также метод GetHashCode (), который учитывает содержимое объекта, а не ссылку на объект.