Check if 'T' inherits or implements a class/interface

后端 未结 8 1812
名媛妹妹
名媛妹妹 2020-12-08 04:00

Is there a way to test if T inherits/implements a class/interface?

private void MyGenericClass ()
{
    if(T ... inherits or implements some class/i         


        
8条回答
  •  遥遥无期
    2020-12-08 04:17

    You can use constraints on the class.

    MyClass where T : Employee
    

    Take a look at http://msdn.microsoft.com/en-us/library/d5x73970.aspx

提交回复
热议问题