What is the difference between having a "Generic Interface" and "Generic method in non generic interface" ? Is there any advantage of one over the other ?
interface IMyInterface
{
void MyMethod<T>(T param) where T : class;
}
and
interface IMyInterface<T> where T : class
{
void MyMethod(T param)
}
Yes, the non-generic method can't force the generic method to have specific type parameters. The generic interface can.
In your IMyInterface<T>.MyMethod, T can only be the exact same type used by the IMyInterface<T>. In IMyInterface.MyMethod, T can be anything (as long as it obeys the type constraint T : class).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With