开发者

How do I specify multiple generic type constraints on a single method?

I can restrict generics to a specify type using the "Where" clause such as:

public void foo<TTypeA>() where TTypeA : class, A

How do I do this if my function has two generic types?

public void foo<TTypeA, TTypeB>() where TTypeA : class, A && TTypeB : class, B

The above doesn't work. 开发者_StackOverflow What's the correct syntax to add the rule "TTypeB : class, B"


 public void foo<TTypeA, TTypeB>() where TTypeA : class, A 
                                   where TTypeB : class, B 


public void foo<TTypeA, TTypeB>() where TTypeA : class, A where TTypeB : class, B

dang, 20s late. Vote for James Curran, he was first.


Something like this?

 public void foo<TTypeA, TTypeB>() where TTypeA : class where TTypeB : class


just replace && with another where

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜