define interface method with different parameters in C#

后端 未结 4 1117
生来不讨喜
生来不讨喜 2021-01-18 14:23
interface parentInterface
{
   public String methodA(/*define parameters name and dataType*/);
}

and

public class childA : parentIn         


        
4条回答
  •  孤独总比滥情好
    2021-01-18 15:01

    You have two different methods

    public String methodA(String a, int b, String c, long d){}
    

    and

    public String methodA(int e, String f, String g){}
    

    that represent two different contracts to childA and childB respectively. You cannot define an interface with a single methodA that fits both definitions. What you seek to do is not possible.

    Note that you could define both overloads in your interface, but then each class implementing that interface would have to implement both overloads.

提交回复
热议问题