Windows Forms Generic Inheritance

前端 未结 2 1497
遇见更好的自我
遇见更好的自我 2020-12-21 00:55

I have these classes:

class Foo : Form 
    where T1, T2 : EventArgs

class MiddleGoo : Foo

class Goo : MiddleGoo

2条回答
  •  春和景丽
    2020-12-21 01:16

    The T2 Type parameter in Foo class needs to be convertible to EventArgs. But when you are defining your Boo class, you aren't including that constraint. Change your Boo class to this:

    class Boo : Foo
        where T1 : EventArgs
        where Y : EventArgs
    

    Also, you have got a syntax error at the Foo class declaration. Change it to :

    class Foo
        where T1 : EventArgs
        where T2 : EventArgs
    

提交回复
热议问题