- No. If an interface is implemented in a base class, the derived class also implements them without having to declare it explictly again.
- Generic interface for different generic arguments must be declared explicitly. The reason is that e.g. an
IEnumerable<int>
is a completely different type than an IEnumerable<string>
that most probably requires the derived class to implement methods with a different signature than the base class.
Example:
public interface IGenericInterface<T>
{
T GetSomething();
void DoSomething(T arg);
}
public class BaseClass : IGenericInterface<int>
{
public virtual int GetSomething() { return 5; }
public virtual void DoSomething(int arg) { Console.WriteLine(arg); }
}
public class Derived : BaseClass, IGenericInterface<string>
{
string IGenericInterface<string>.GetSomething() { return "hello world!"; }
public void DoSomething(string arg) { Console.WriteLine(arg); }
}
Note that in this example the Derived.GetSomething()
needs to be implemented explicitly, because otherwise it would conflict with the base class' int
version. Methods with the same name are not allowed to only differ in their return types.