What does “where T : somevalue” mean?

前端 未结 4 1244
暖寄归人
暖寄归人 2021-02-05 22:14

What does where T : somevalue mean? I just saw some code that said where T : Attribute. I think this has something to do with generics but I am not sur

4条回答
  •  情书的邮戳
    2021-02-05 22:45

    It's a way of restricting the type used as generic arguments. So:

    where T : SomeType
    

    Means that T must either derive from SomeType or implement the interface SomeType

提交回复
热议问题