Casting and templates...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oriane

    #1

    Casting and templates...

    Hi there

    The following code doesn't complie:
    _______________ _______________ _______________ ___________
    public interface ITree
    {
    ITree GetFather ();
    List<ITreeGetCh ildren();
    }


    public class A : ITree
    {
    protected A m_father;
    protected List<Am_ListChi ldren;

    public ITree GetFather() { return m_father; }
    public List<ITreeGetCh ildren() { return m_ListChildren; }
    }
    _______________ _______________ _______________ ___________

    since "Error 2 Cannot implicitly convert type
    'System.Collect ions.Generic.Li st<XMLTreeview. A>' to
    'System.Collect ions.Generic.Li st<XMLTreeview. ITree>'

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

    Oriane

  • Alex Meleta

    #2
    Re: Casting and templates...

    Hi Oriane,

    Classes use polymorphism till they are not generic types :)
    So, you can use something like this "new List<ITree>(m_L istChildren.ToA rray());"
    to convert the values.

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


    O......
    Opublic class A : ITree
    O{
    Oprotected A m_father;
    Oprotected List<Am_ListChi ldren;
    Opublic ITree GetFather() { return m_father; }
    Opublic List<ITreeGetCh ildren() { return m_ListChildren; }
    O} .....
    OHowever A inherits from ITree, so the cast should be working no... Is
    Othere any workaround ?


    Comment

    • Oriane

      #3
      Re: Casting and templates...


      "Alex Meleta" <ameleta@gmail. coma ecrit dans le message de
      news:150f6b305b 9288c9ea15590b1 862@msnews.micr osoft.com...
      Hi Oriane,
      >
      Classes use polymorphism till they are not generic types :)
      Good point :-(
      So, you can use something like this "new
      List<ITree>(m_L istChildren.ToA rray());" to convert the values.
      Set and match !!

      Thanks !!

      Comment

      Working...