C# accessing a static property of type T in a generic class

前端 未结 7 1516
后悔当初
后悔当初 2020-12-16 09:30

I am trying to accomplish the following scenario that the generic TestClassWrapper will be able to access static properties of classes it is made of (they will all derive fr

7条回答
  •  生来不讨喜
    2020-12-16 09:48

    Surely you can just write this:

    public int test() 
    { 
        return TestClass.x; 
    } 
    

    Even in a nontrivial example, you can't override a static field so will always call it from your known base class.

提交回复
热议问题