【发布时间】:2015-03-21 00:13:52
【问题描述】:
好日子,
假设我有一个静态 List<AClass> 对象(我们将其命名为 myStaticList),其中包含另一个列表,并且该列表包含另一个具有 CId 和 Name 属性的列表。
我需要做的是
foreach(AClass a in myStaticList)
{
foreach(BClass b in a.bList)
{
foreach(CClass c in b.cList)
{
if(c.CId == 12345)
{
c.Name = "Specific element in static list is now changed.";
}
}
}
}
我可以使用 LINQ Lambda 表达式实现这一点吗?
类似的东西;
myStaticList
.Where(a=>a.bList
.Where(b=>b.cList
.Where(c=>c.CId == 12345) != null) != null)
.something logical
.Name = "Specific element in static list is now changed.";
请注意,我想更改静态列表中该特定项目的属性。
【问题讨论】:
-
Linq nested list expression 的可能重复项