Public property List needs to Concat 2 types with inheritance
- by Bernard
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?
}