.NET 2.0 Generics and type casting

K

Kris

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
 
B

Barry Kelly

Kris said:
Hi,

I am trying to create a new generic class and am having trouble casting
a generic type to a specific type. For example,

I already posted a solution to your problem.

-- Barry
 
K

Kris

Sorry about that. After several hours, my newsreader indicated that it
still wasn't
posted and I tried again.


Kris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top