开发者

How to define constrains for multiple different generic types

I have following interfaces defined

interface IStoreItem
{

}

interface ILoadItem
{

}

Now I would like to implement a collection which can handle items of these interafeces but usually a class which realises IStoreItem will not realise ILoadItem. So is there some way I can define a constrain like this:

p开发者_开发问答ublic class NetworkingCollection<T> : List<T>
   where T : IStoreItem or ILoadItem
{

}


This is not supported.

You will need a different class for each interface you want to constrain to.


Alternatively, if you inherit IStoreItem and ILoadItem from a common interface (say IGenericItem), you could constrain to the parent interface.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜