In C# it’s possible to defined a method parameter with two interface restrictions. This with bounds. For example.
interface IA
{
int A {get;}
}
interface IB
{
int B {get;}
}
void Foo<T>(T param1) where T: IA, IB {}
So two interfaces, and the first parameter (param1) of the method Foo should implement both interfaces.
But is this really useful? AFAIK it’s not possible to cast an object to multiple interfaces in C#? Of course a class can implement two interfaces.
This is very useful if the templatized class requires functionality from multiple interfaces. For instance maybe you require classes to be comparable to one another, IComparable, and you also want to make sure the user of your template class remembers to override
ToString()so the data can be displayed, IFormattable.That is somewhat of a contrived answer but being able to specify precise interfaces multiple times allow you to keep functionality in its interface without getting one cluttered.