我有这样的东西:
public interface IExample
{
int GetInteger()
T GetAnything(); //How do I define a function with a generic return type???
^^^^^
}
这可能吗???
最佳答案
如果整个界面应该是通用的:
public interface IExample<T>
{
int GetInteger();
T GetAnything();
}
如果只是方法需要泛型:
public interface IExample
{
int GetInteger();
T GetAnything<T>();
}
关于指定通用返回类型的 C# 接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10147292/