Riv*_*ver 17 c# generics interface
我有类似的东西:
public interface IExample
{
int GetInteger()
T GetAnything(); //How do I define a function with a generic return type???
^^^^^
}
Run Code Online (Sandbox Code Playgroud)
这可能吗???
Fem*_*ref 47
如果整个界面应该是通用的:
public interface IExample<T>
{
int GetInteger();
T GetAnything();
}
Run Code Online (Sandbox Code Playgroud)
如果只有方法需要通用:
public interface IExample
{
int GetInteger();
T GetAnything<T>();
}
Run Code Online (Sandbox Code Playgroud)
小智 5
public interface IExample<T>
{
int GetInteger()
T GetAnything();
}
Run Code Online (Sandbox Code Playgroud)
Tadaa :)!
或者,您可以只返回System.Object并将其转换为您想要的任何内容.
| 归档时间: |
|
| 查看次数: |
20720 次 |
| 最近记录: |