C# generics: using class generic in where clause of method generic -


can explain why isn't possible (at least in .net 2.0):

public class a<t> {     public void method<u>() u : t     {         ...     } }  ...  a<k> obj = new a<k>(); obj.method<j>(); 

with k being superclass of j

edit

i've tried simplify problem in order make question more legible, i've overdo that. sorry!

my problem little more specific guess. code (based on this):

public class container<t> {     private static class pertype<u> u : t     {         public static u item;     }      public u get<u>() u : t     {         return pertype<u>.item;     }      public void set<u>(u newitem) u : t     {         pertype<u>.item = newitem;     } } 

and i'm getting error:

container.cs(13,24): error cs0305: using generic type container<t>.pertype<u>' requires2' type argument(s)

actually possible. code compiles , runs fine:

public class a<t> {     public void act<u>() u : t     {         console.write("a");     } }  static void main(string[] args) {   a<ienumerable> = new a<ienumerable>();   a.act<list<int>>(); } 

what not possible using covariance / contravariance in generics, explained here:

ienumerable<derived> d = new list<derived>(); ienumerable<base> b = d; 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -