Is there a way to do the following with Linq:
foreach (var c in collection)
{
if (c.Condition == condition)
{
c.PropertyToSet = value;
}
else
{
c.PropertyToSet = otherValue;
}
}
To clarify, I want to iterate over each object in the collection and then update the property for each object, except for one element of my collection, which should be updated to a different value.
At this point, I am using a counter to verify that I am setting my value to one and only one element of my collection. I removed it from this example so that people offer other solutions.
The original question, without exception, in the collection here
EDIT
I ask this question because I'm not sure if this can be done with LinQ. so your answers reassure my opinion of LinQ. Thank.
source
share