Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 其中T:<;界面>;其中T:class给出了cs0452_C#_Generics - Fatal编程技术网

C# 其中T:<;界面>;其中T:class给出了cs0452

C# 其中T:<;界面>;其中T:class给出了cs0452,c#,generics,C#,Generics,我有 公共静态void SecureTcpRpc(字符串uri, 行动(行动) 其中InterfaceType:class; 那我就用这个 public static void SecureTcpRpc<InterfaceType>(string uri, Action<InterfaceType> action)

我有

公共静态void SecureTcpRpc(字符串uri,
行动(行动)
其中InterfaceType:class;
那我就用这个

public static void SecureTcpRpc<InterfaceType>(string uri, 
                                               Action<InterfaceType> action) 
                                              where InterfaceType : class;
private static AuthorizedActionResult
RunChannelAction(IEnumerable URI,
函数(函数)
其中T:IPingable
{
WcfClient.SecureTcpRpc。。。。

编译器不喜欢我将T约束为IPingable。我不明白为什么它会对象。IPingable是引用类型,因此它与SecureTPCRP方法上的约束匹配。但是编译器说“T必须是引用类型”

第二个类型是否应该是泛型的?如果它是接口类型,则应该类似于:

 private static AuthorizedActionResult 
                RunChannelAction<T>(IEnumerable<string> uris, 
                                    Func<T, AuthorizedActionResult> actionFunc)
                                    where T : IPingable
            {
                    WcfClient.SecureTcpRpc<T>....
private static AuthorizedActionResult RunChannelAction(
IEnumerable URI,
函数(函数)
{
WcfClient.SecureTcpRpc。。。。
我认为您还需要对
AuthorizedActionResult
函数设置“class”约束,才能使其正常工作

private static AuthorizedActionResult RunChannelAction(
  IEnumerable<string> uris, 
  Func<IPingable, AuthorizedActionResult> actionFunc)
        {
                WcfClient.SecureTcpRpc<IPingable>....

这两个函数之间的关系是什么?结构(值类型)也可以实现接口。@Cameron-啊哈,我总是忘记是的,我在Cameron的注释(类优先于tho)+1之后得出了这个结论。这也是我最初的反应。这里完全不需要泛型类型参数。
where T : class, IPingable