Update foreach in foreach c#
This overwrites a.Image
for every item in listDetail
, therefore you get the last Image
:
foreach (var item in listDetail)
{
a.Image = item.Image;
}
As you have an Id
property, I suggest using it for synchronization:
foreach (var item in listDetail)
{
if (item.Id == a.Id)
{
a.Image = item.Image;
break;
}
}
I added a break;
so you break out of the loop as soon as you found a match.