views:

29

answers:

1

I have an abstract class as follow:

class BaseReturnType { }    
class DerivedReturnType : BaseReturnType { }    

abstract class BaseClass<T> where T : BaseReturnType    
{        
  public abstract T PolymorphicMethod();    
}    

class DerivedClass : BaseClass<DerivedReturnType>    
{
  public override DerivedReturnType PolymorphicMethod()        
  {            
    return new DerivedReturnType();        
  }    
}

So if add exta parrameter for Generic called T2 how do I put extrac constraining on this?

abstract class BaseClass<T, **T2**> where T : BaseReturnType ???  
    {        
      public abstract T PolymorphicMethod();    
    }
+4  A: 
abstract class BaseClass<T, **T2**> where T : BaseReturnType where T2 : BaseTypeForT2

    {        
      public abstract T PolymorphicMethod();    
    }

as per here.

Otávio Décio
More easily found in the "Constraining Multiple Parameters" section of http://msdn.microsoft.com/en-us/library/d5x73970.aspx
outis