[英]C# How to make Dictionary<Type,Generic<Type>>?
[英]How make a collection of type which is generic type in c#
我有以下课程
public class Relation<T1, T2> where T1: Entity where T2: Entity
{
}
我想使类从关联类型的列表/集合派生
public class RelationList<T>: List<Relation>>
{
}
我已经尝试过了,但是无法解决问题。 即使正确指向SO也将有所帮助
因为您的Relation
类是泛型的,所以在从Relation
派生时必须指定泛型类型。
要么作为
public class RelationList: List<Relation<MyEntity2, MyEntity2>>
{
}
或作为
public class RelationList<T1, T2> : List<Relation<T1, T2>>
where T1: Entity
where T2: Entity
{
}
如果您希望RelationList
能够保持Relation<T1, T2>
无论如何指定T1
和T2
都应该使用其他接口:
public interface IRelation
{
}
public class Relation<T1, T2> : IRelation
where T1: Entity where T2: Entity
{
}
public class RelationList : List<IRelation>
{
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.