mardi 30 septembre 2014

LINQ query to update property of a list


Vote count:

0




I am trying to convert the following code to 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;
}
}
}


I tried the following query :



(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;
});
});


But i get an error when TestList is null in the list. I am not sure what I am doing wrong here.



asked 2 mins ago







LINQ query to update property of a list

Aucun commentaire:

Enregistrer un commentaire