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]动态?
将返回类型声明为Object,或使用通用接口:
public interface TestInterface<T> {
T MethodHere();
}
public class test3 : TestInterface<int> {
int MethodHere() {
return 2;
}
}
Run Code Online (Sandbox Code Playgroud)