I have this code and want to do the same with a linq statement.
foreach (var field in fieldExtension)
{
if (field.Name.Equals(item.Name))
{
field.Access = true;
}
}
It is easy to iterate over the list with:
fieldExtension.Where(field => field.Name.Equals(item.Name));
But is it posible to assign a value to the variable we have found in the list? I thought about something like this:
fieldExtension.Where(field => field.Name.Equals(item.Name)).Select(field => field.Access = true);
Does anybody know a way to do it correctly with linq? Because I don't want to split it up. Which would also work.
var result = fieldExtension.Where(field => field.Name.Equals(item.Name)).ToList();
result.FirstOrDefault().Access = true;