this is something really simple Im sure, but Im struggling to get my head around the inheritance malarky when it comes to interfacing.
Given the following classes, how do I interface the Get method in an interface specific to class Parent, without overriding the base method?
public class Base<T, T2>
{
public T Get<T, T2>(string key)
{
...
}
}
public class Parent : Base<Type1, Type2>, IParent
{
...
}
Here’s what I have atm, but I keep getting a “inteface member Type1 IParent.Get(string) is not implemented” error.
public interface IParent
{
Type1 Get(string key);
}
The
T Get<T,T2>(string)method ofBase<T,T2>and the methodType1 Get(string)method ofIParentare two different method signatures. You would need to implement both. If you wanted both implementations to use the same functionality you could do the following:However I believe that your original intent is not to parameterize the
Get()method inBase<T,T2>therefore you would writeBaselike so:That signature would satisfy the method signature in
IParent.You only need type parameters (e.g.
TandT2) on methods when the type cannot or should not be inferred by the class that contains the method.