Will the Enumerable.Distinct method remove all duplicates from a collection implementing IEnumerable even if it is not sorted?
I’m coming from a C++ background and wonder if Distinct behaves similiar to C++ unique algorithm where the sequence has to be sorted.
Yes.
Note that you need to implement the
IEqualityComparer<T>interface and it’sEqualsandGetHashCodemethods for custom types.