c# - 泛型双接口(interface)

标签 c# .net generics wildcard

public interface IFoo
public class Foo : IFoo
public interface ILang<T> where T:IFoo
public class Lang : ILang<Foo>

但是现在,我想要这样的带通配符的东西

public class CarroMontadora<T> where T:ILang<?>

因为这不适用于我的界面:

public class MYCLASS<T> where T:ILang<IFoo>

这不是太聪明,因为不是那么泛型:

public class MYCLASS<T,U> where T:ILang<U> where U: IFoo

最佳答案

您必须向新类添加另一个通用参数:

public class CarroMontadora<T1, T2>
    where T2 : IFoo
    where T1 : ILang<T2>
{
}

关于c# - 泛型双接口(interface),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21054666/

相关文章:

c# - 当命令在 .NET 中的 FTP 服务器上失败时会发生什么?

c# - 防止TcpClient的NetworkStream ReadTimeout关闭套接字

c# - 在 C# 中使用外部 C++ 库

.net - 存储大量文件的最佳方式

scala - 关于 Java 和 Scala 中的泛型

ios - 快速在通用类中实现协议(protocol)

java - 泛型和流 : How to make this into a `StreamTuple::new` statement?

c# - ASP.Net Core MVC Identity - 添加临时( session )声明

c# - Entity Framework 5 将现有实体添加到嵌套集合

c# - TimeZoneInfo.ConvertTime 在 DateTime.MinValue 上非常慢