K
Kris Jennings
Hi,
I am trying to create a new generic class and am having trouble casting
a generic type to a specific type. For example,
public class MyClass<T> where T : MyItemClass, new()
{
public MyClass() { }
public void AppendItem()
{
T myItem = new T();
myItem.Parent = this;
}
}
public class MyItemClass
{
public MyClass<MyItemClass> Parent;
public MyItemClass() { }
}
fails to compile with the error: Cannot implicitly convert type
'GenericInheritanceTst.MyClass<T>'
to 'GenericInheritanceTst.MyClass<GenericInheritanceTst.MyItem Class>'.
Has anyone seen this problem and found a resolution?
Thanks.
Kris
I am trying to create a new generic class and am having trouble casting
a generic type to a specific type. For example,
public class MyClass<T> where T : MyItemClass, new()
{
public MyClass() { }
public void AppendItem()
{
T myItem = new T();
myItem.Parent = this;
}
}
public class MyItemClass
{
public MyClass<MyItemClass> Parent;
public MyItemClass() { }
}
fails to compile with the error: Cannot implicitly convert type
'GenericInheritanceTst.MyClass<T>'
to 'GenericInheritanceTst.MyClass<GenericInheritanceTst.MyItem Class>'.
Has anyone seen this problem and found a resolution?
Thanks.
Kris