I have foreach
code block in a method, I'm using this many places.
"Title" is a String type property of "UsefulLinks" class which I mention "Before". But I want to assign that property with my String variable which is fieldName. How can we reach an instance and assign its value?
Before:
foreach (var item in vm.UsefulLinks)
{
item.Title = usefullLinkTranslations
.LastOrDefault(t => t.FieldName == fieldName)
?.Value;
}
After:
foreach (var item in vm.UsefulLinks)
{
item.["fieldName"]= usefullLinkTranslations
.LastOrDefault(t => t.FieldName == fieldName)
?.Value;
}