[英]Updating data of a nested list with linq
我有一個包含嵌套列表的用戶對象,我需要更改第三個列表中元素的值並返回該用戶對象。
我想用linq做到這一點,下面是嵌套循環。
foreach (User itm in user)
{
if (itm.destinations!=null)
{
foreach (Models.Api.destinations.Destination dm in itm.destinations)
{
if (dm.destinationData != null)
{
foreach (Models.Api.destinations.DestinationData destData in dm.destinationData)
{
if (destData.type == "phone" & destData.data!="")
{
//i want to update the destData.data here .. something like
destData.data ='updated data';
}
}
}
}
}
}
我希望更新的數據在用戶對象中可用
有人可以通過LINQ幫助我實現這一目標嗎
在此先感謝Tarak
嘗試這個:
foreach (var x in
(from itm in user
where itm.destinations!=null
from dm in itm.destinations
where dm.destinationData != null
from destData in dm.destinationData
where destData.type == "phone" & destData.data != ""
select new { itm, dm, destData }))
{
/* put your update code here. */
}
您沒有給我們提供更新代碼的外觀,甚至沒有給我們提供要使用的對象模型。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.