No, I'm afraid you cannot specify such a restriction. (I also wanted this).
You can write a static universal method with two type parameters in a non-universal class:
public delegate bool EqualityComparer<T>(T x, T y); public class Collection { public static Equals<T, U>(Collection<T> first, Collection<T> second, EqualityComparer<U> comparer) where T : U { } }
and you can even make this call an instance method in a generic class if you want:
// Implementing the static method: return first.Equals(second, new EqualityComparer<T>(comparer));
where the collection instance method will only be:
public bool Equals(Collection<T> other, EqualityComparer<T> eq) {
This takes advantage of contraception, available for creating delegates from C # 2 onwards.
Jon skeet
source share