我有2個列表:A類型和Aa類型之一。 AA型是由A型 所以繼承:公共屬性列表需要Concat 2繼承類型
List<A> listA = new List<A>();
List<Aa> listAa = new List<Aa>();
與
class Aa : A
我:
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);
}
}
我可以以某種方式使用,而不是foreach循環的毗連?即
get
{
return listA.Concat(listAa);
} // this doesn't work
其次,我該如何做屬性的設置部分?
set
{
//figure out the type of variable value and put into appropriate list?
}
@Obalix:從原來的,我不是100%肯定這些都是通用的清單,而不是System.Collections.List .. – 2010-03-22 16:26:24
@Reed Copsey:剛做格式化...... :-) ......根據Bernard的OP,列表被定義爲列表和列表。 –
AxelEckenberger
2010-03-22 16:33:03
啊,好吧 - 從原始文本中並不明顯,它包含:「List listA = new List();」等等,表明非泛型用法。 – 2010-03-22 16:50:53