我想下面的代码转换为LINQ的财产:LINQ查询来更新列表
for (int i = 0; i < List.Count;i++)
{
List[i].IsActive = false;
if(List[i].TestList != null)
{
for(int j = 0;j<List[i].TestList.Count;j++)
{
List[i].TestList[j].IsActive = false;
}
}
}
我尝试以下查询:
(from s in List select s).ToList().ForEach((s) =>
{
s.IsActive = false;
(from t in s.TestList where t != null select t).ToList().ForEach((t) =>
{
t.IsActive = false;
});
});
,但我得到一个错误,当TestList是在列表中为null。我不确定我在这里做错了什么。
''之前收集这所有项目,其中T是'null' 。也许'(从s.TestList中的t,其中t!= null选择t)' – Fabio 2014-10-01 05:39:34
我的错误,它是t!= null我输入错了。但是,我仍然得到错误。 – perplexedDev 2014-10-01 17:08:37