Is not possible (except use different name) to have several generic methods with the same name but implementing different interface ?
public IList<T> List<T>() where T : class, IMyInterface1
{
return mylist
}
public IList<T> List<T>() where T : class, IMyInterface2
{
return mylist
}
Thanks,
No, you can’t overload just by generic type constaints. You can overload by the number of type parameters, but not on their constraints.
If you’re implementing an interface you can use explicit interface implementation – otherwise I’d suggest just using different names. I often find that using different names makes things clearer anyway, to be honest.
Bear in mind that the example you’ve given introduces natural ambiguity anyway – what would you expect to be called if the type argument implemented both interfaces?