其中T:到其中T:类提供cs0452
问题描述:
我其中T:<interface>到其中T:类提供cs0452
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>....
编译器不喜欢,我已经制约吨至是IPingable。我不明白它为什么反对。 IPingable是一个引用类型,因此它与SecureTpcRpc方法上的约束相匹配。但是编译器说,“T必须是引用类型”
答
我认为你需要在AuthorizedActionResult
功能也为它工作的“类”的约束。
where T : class, IPingable
+0
是我在Camerons评论(班上第一次) – pm100
答
如果第二个是通用的?如果是接口类型,它应该是这样的:
private static AuthorizedActionResult RunChannelAction(
IEnumerable<string> uris,
Func<IPingable, AuthorizedActionResult> actionFunc)
{
WcfClient.SecureTcpRpc<IPingable>....
+0
+1这也是我最初的反应。通用类型参数在这里完全没有必要。 – spender
什么是这两个函数的关系? –
结构体(值类型)也可以实现接口。 – Cameron
@Cameron - 哈哈,我总是忘记 – pm100