Is it possible to define a function that takes in a parameter that must implement two interfaces?
(The two interfaces are ones I just remembered off the top of my head; not the ones I want to use)
private void DoSomthing(IComparable, ICollection input) { }
A class can implement more than one interface at a time. A class can extend only one class, but implement many interfaces. An interface can extend another interface, in a similar way as a class can extend another class.
A class implementation of a method takes precedence over a default method. So, if the class already has the same method as an Interface, then the default method from the implemented Interface does not take effect. However, if two interfaces implement the same default method, then there is a conflict.
But if you really really want to know the theoretical maximum number of interfaces a class can implement, it's 65535.
You can:
1) Define an interface that inherits both required interfaces:
public interface ICombinedInterface : IComparable, ICollection {... } private void DoSomething(ICombinedInterface input) {... }
2) Use generics:
private void DoSomething<T>(T input) where T : IComparable, ICollection {...}
You can inherit another interface from those two interfaces and make your parameter implement that interface.
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