Skip to content

Instantly share code, notes, and snippets.

@thomaslevesque
Last active December 20, 2015 09:19
Show Gist options
  • Save thomaslevesque/6107331 to your computer and use it in GitHub Desktop.
Save thomaslevesque/6107331 to your computer and use it in GitHub Desktop.
Distinct overload with 2 type parameters, to solve the problem shown on Eric Lippert's blog (http://ericlippert.com/2013/07/29/a-contravariance-conundrum/)
public static IEnumerable<T> Distinct<T, U>(this IEnumerable<T> source, IEqualityComparer<U> comparer)
where T : U
{
IEqualityComparer<T> comparer2 = (IEqualityComparer<T>)comparer;
return Enumerable.Distinct<T>(source, comparer2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment