Casting and templates...

Casting and templates...

am 31.10.2007 18:09:40 von Oriane

Hi there

The following code doesn't complie:
________________________________________________________
public interface ITree
{
ITree GetFather ();
List GetChildren();
}


public class A : ITree
{
protected A m_father;
protected List m_ListChildren;

public ITree GetFather() { return m_father; }
public List GetChildren() { return m_ListChildren; }
}
________________________________________________________

since "Error 2 Cannot implicitly convert type
'System.Collections.Generic.List' to
'System.Collections.Generic.List'

However A inherits from ITree, so the cast should be working no...
Is there any workaround ?

Oriane

Re: Casting and templates...

am 31.10.2007 18:40:03 von Alex Meleta

Hi Oriane,

Classes use polymorphism till they are not generic types :)
So, you can use something like this "new List(m_ListChildren.ToArray());"
to convert the values.

Regards, Alex
[TechBlog] http://devkids.blogspot.com


O> ......
O> public class A : ITree
O> {
O> protected A m_father;
O> protected List
m_ListChildren;
O> public ITree GetFather() { return m_father; }
O> public List GetChildren() { return m_ListChildren; }
O> } .....
O> However A inherits from ITree, so the cast should be working no... Is
O> there any workaround ?

Re: Casting and templates...

am 01.11.2007 21:21:17 von Oriane

"Alex Meleta" a ecrit dans le message de
news:150f6b305b9288c9ea15590b1862@msnews.microsoft.com...
> Hi Oriane,
>
> Classes use polymorphism till they are not generic types :)
Good point :-(
> So, you can use something like this "new
> List(m_ListChildren.ToArray());" to convert the values.
Set and match !!

Thanks !!