Can anyone explain why this is not possible (at least in .Net 2.0):
public class A<T>
{
public void Method<U>() where U : T
{
...
}
}
...
A<K> obj = new A<K>();
obj.Method<J>();
where K is a superclass of J
EDIT
I tried to simplify the problem to make the question more understandable, but I clearly overdid it. Excuse me!
My problem is a little more specific, I think. This is my code (based on this ):
public class Container<T>
{
private static class PerType<U> where U : T
{
public static U item;
}
public U Get<U>() where U : T
{
return PerType<U>.item;
}
public void Set<U>(U newItem) where U : T
{
PerType<U>.item = newItem;
}
}
and I get this error:
Container.cs (13,24): error CS0305: using generic type Container<T>.PerType<U>' requires2 'type argument
source
share