Reputation: 13575
For example
void f<C, T>(C<T> collection, T element) : where C has member method BindarySearch
I have two questions:
Upvotes: 0
Views: 77
Reputation: 1640
You can use an interface to enforce the required members:
interface IHasBinarySearch<T> : ICollection<T> {
int BinarySearch(T item);
}
Then a generic method can be defined like so:
void f<C, T>(C collection, T element) where C : IHasBinarySearch<T>
This interface is already a generic collection (by extending ICollection<T>
) so no need to specify the constraint on the method again.
Upvotes: 1