开发者

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

开发者 https://www.devze.com 2023-01-05 21:18 出处:网络
I can restrict generics to a specify type using the \"Where\" clause such as: public void foo<TTypeA>() where TTypeA : class, A

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

精彩评论

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