Create relationship between two type parameters : Generic Class : Generics C# Source Code


Custom Search

C# Source Code » Generics » Generic Class »

 

Create relationship between two type parameters








    


using System;

class A {
}

class B : A {
}

// Here, V must inherit T.
class Gen<T, V> where V : T {
}

class Test {
  public static void Main() {

    // This declaration is OK because B inherits A.
    Gen<A, B> x = new Gen<A, B>();

    // This declaration is in error because
    // A does not inherit B.
//    Gen<B, A> y = new Gen<B, A>();

  }
}
           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Generics
» Generic Class