我有
public static void SecureTcpRpc<InterfaceType>(string uri,
Action<InterfaceType> action)
where InterfaceType : class;
然后我在这里使用它
private static AuthorizedActionResult
RunChannelAction<T>(IEnumerable<string> uris,
Func<T, AuthorizedActionResult> actionFunc)
where T : IPingable
{
WcfClient.SecureTcpRpc<T>....
编译器不喜欢我将 T 限制为可 IPing。我不明白它为什么反对。 IPingable 是引用类型,因此它与 SecureTpcRpc 方法上的约束相匹配。但是编译器说“T 必须是引用类型”
最佳答案
我认为您还需要对 AuthorizedActionResult
函数进行“类”约束才能使其正常工作。
where T : class, IPingable
关于c# - 其中 T : <interface> into where T: class gives cs0452,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10376383/