接口方法的成员有不同的类型

Tim*_*sen 0 c# types interface member

我有这个界面

public interface TestInterface
{
   [returntype] MethodHere();
}

public class test1 : TestInterface
{
   string MethodHere(){
      return "Bla";
   }
}

public class test2 : TestInterface
{
   int MethodHere(){
     return 2;
   }
}
Run Code Online (Sandbox Code Playgroud)

有没有办法让[returntype]动态?

x0n*_*x0n 5

将返回类型声明为Object,或使用通用接口:

public interface TestInterface<T> {
    T MethodHere();
}

public class test3 : TestInterface<int> {
   int MethodHere() {
      return 2;
   }
}
Run Code Online (Sandbox Code Playgroud)