Reputation: 1303
How can I convert below foreach to linq? I need to get the element.
foreach (var x in LoadData)
item.Comments = x.Inventory.Comments;
Upvotes: 0
Views: 79
Reputation: 3279
Maybe, you want to use Select
function:
LoadData.Select(x => x.Inventory.Comments);
Edit:
And if you want to get last element, you can use Last
function:
LoadData.Select(x => x.Inventory.Comments).Last();
Or
LoadData.Last().Inventory.Comments;
Upvotes: 2