Public property List needs to Concat 2 types with inheritance

Posted by Bernard on Stack Overflow See other posts from Stack Overflow or by Bernard
Published on 2010-03-22T16:20:45Z Indexed on 2010/03/22 16:31 UTC
Read the original article Hit count: 314

Filed under:
|
|
|

I have 2 lists: one of type A and one of type Aa. type Aa is inherited from type A. So:

List<A> listA = new List<A>();
List<Aa> listAa = new List<Aa>();

with

class Aa : A

I have:

public property Lists<A>
{
  get
   {
    List<A> newList = new List<A>();
    //return concat of both lists
    foreach(List l in listA)
    {
      newList.Add(l);
    }
    foreach(List l in listAa)
    {
      newList.Add(l);
    }
}

Can I somehow use Concat instead of the foreach loop? i.e.

get
{
  return listA.Concat(listAa);
} // this doesn't work

And secondly, how do I do the set part of the property?

set
{
  //figure out the type of variable value and put into appropriate list?
}

© Stack Overflow or respective owner

Related posts about c#

Related posts about list