【发布时间】:2010-03-22 16:20:45
【问题描述】:
我有 2 个列表:一个 A 类型,一个 Aa 类型。 Aa 类型继承自 A 类型。 所以:
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);
}
}
我可以以某种方式使用 Concat 代替 foreach 循环吗?即
get
{
return listA.Concat(listAa);
} // this doesn't work
其次,属性的set部分怎么做?
set
{
//figure out the type of variable value and put into appropriate list?
}
【问题讨论】:
-
@Obalix:从最初来看,我不能 100% 确定这些是通用列表,而不是 System.Collections.List...
-
@Reed Copsey:刚刚进行了格式化... :-) ... 根据 Bernard 的 OP,列表被定义为 List 和 List
。 -
啊,好吧 - 从原始文本中看不出来,它有:“List listA = new List();”等...暗示非通用用法。
标签: c# linq list ienumerable