Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/335.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.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# 如何使用.Net泛型继承模板参数?_C#_.net_Generics - Fatal编程技术网

C# 如何使用.Net泛型继承模板参数?

C# 如何使用.Net泛型继承模板参数?,c#,.net,generics,C#,.net,Generics,我希望能够做到这一点。 MyInterface interface = new ServiceProxyHelper<ProxyType>(); 这行吗? public class ProxyType : MyInterface {} public class ServiceProxyHelper<ProxyType> : IDisposable, MyInterface {} 公共类代理类型:MyInterface{} 公共类ServiceProxyHelper:

我希望能够做到这一点。

MyInterface interface = new ServiceProxyHelper<ProxyType>();
这行吗?

public class ProxyType : MyInterface {}

public class ServiceProxyHelper<ProxyType> : IDisposable, MyInterface {}
公共类代理类型:MyInterface{}
公共类ServiceProxyHelper:IDisposable,MyInterface{}

我想这就是你想要做的:

public class ServiceProxyHelper<T> where T : MyInterface { ... }
公共类ServiceProxyHelper,其中T:MyInterface{…}
相关问题:
public class ServiceProxyHelper<T> where T : MyInterface { ... }