In C# 4.0, is it possible to derive a class from a generic type parameter?

后端 未结 4 2145
一向
一向 2020-12-06 04:18

I\'ve been trying this, but I can\'t seem to figure this out. I want to do this...

public abstract class SingletonType : TBase         


        
4条回答
  •  甜味超标
    2020-12-06 05:10

    Every type has exactly 1 real, discrete parent class, even when generics are involved. Even when dealing with an open generic type (e.g., typeof(List<>)), you can still find the parent class.

    If what you wanted were allowed, this would not be true, typeof(SingletonType<,> would not have a parent type, and this is not allowed.

提交回复
热议问题