我怀疑你的意思是:
public interface IBOB<T> where T:struct
{
T GetValue();
}
Run Code Online (Sandbox Code Playgroud)
那么YAY:IBOB<bool>它支持的其他类型:
class YAY : IBOB<bool>
{
public bool GetValue()
{
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,由于命名/解析,您可能需要对多种类型使用显式接口实现:
class YAY : IBOB<bool>, IBOB<int>
{
bool IBOB<bool>.GetValue() => true;
int IBOB<int>.GetValue() => 42;
}
Run Code Online (Sandbox Code Playgroud)
如果YAY:IBOB(您的原始),那么您将需要该方法是通用的:
public bool GetValue<T>() {...}
Run Code Online (Sandbox Code Playgroud)
否则它与签名不符.
| 归档时间: |
|
| 查看次数: |
72 次 |
| 最近记录: |