How to use same interface two times with diferrent template parameters, in an interface?

后端 未结 6 1548
谎友^
谎友^ 2020-12-06 14:02

I Think it would be more clearer with this example. We Want to see two methods with diferrent parameters in the processor class. \"int Process (int value);\" \"double Proce

6条回答
  •  渐次进展
    2020-12-06 14:28

    From what I understand, you want to define an interface like this one:

    public interface IRoot
      where TM : MType
      where TPM : PMType
      where TPK : new()
    {
      TM Get(TPK key);
      TPM Get(TPK key);
    }
    

    And this is not possible, because you can't define two methods with the same name and the same parameters.

    error CS0111: Type 'IRoot' already defines a member called 'Get' with the same parameter types
    

    Try to define your interface directly (without inheritance) and change the method names. For example:

    public interface IRoot
      where TM : MType
      where TPM : PMType
      where TPK : new()
    {
      TM GetTM(TPK key);
      TPM GetTPM(TPK key);
    }
    

提交回复
热议问题