C# Define base class by

后端 未结 4 1045
耶瑟儿~
耶瑟儿~ 2021-01-14 03:11

I am trying to find a way to derive a class from a generic base class. Say:

sealed public class Final : Base
{

}

public class Base

        
4条回答
  •  囚心锁ツ
    2021-01-14 03:39

    You could only do this if Final would be a generic class as well, like so:

    public sealed class Final : Base
    

    Then you can put a type restraint on T as either a class, to allow only reference types as T, or an instance of Base, to allow only types that derive from Base:

    public class Base where T : Base
    

提交回复
热议问题