通用基类,其中T是其他通用基类

时间:2010-11-20 18:43:35

标签: c# generics

我有一个抽象的泛型类:

public abstract class SomeBaseClass<U,V>
{
}

我想创建其他泛型类:

public abstract class SomeOtherBaseClass<T1, T2> where T1 : SomeBaseClass<U,V>
{
    private readonly T1 _someBaseClass;

    public SomeOtherBaseClass(T1 someBaseClass)
    {
        _someBaseClass = someBaseClass;
    }
}

我该怎么做?

3 个答案:

答案 0 :(得分:3)

public abstract class SomeOtherBaseClass<T1, T2, U, V>
    where T1 : SomeBaseClass<U, V>

答案 1 :(得分:1)

这可能会为您提供所需:

public abstract class SomeOtherBaseClass<U, V, T2> 
{
    private readonly SomeBaseClass<U, V> _someBaseClass;

    public SomeOtherBaseClass(SomeBaseClass<U, V> someBaseClass)
    {
        _someBaseClass = someBaseClass;
    }
}

答案 2 :(得分:0)

public abstract class SomeOtherBaseClass<T1, T2> where T1 : SomeBaseClass<T1,T2>