LINQ is designed not to have any side effects in general. I tend to add an
extension method to my projects that looks like:
public static void Apply<T>(this IEnumerable<T> items, Action<T> action)
{
foreach(var item in items) action(item);
}
Then you can rewrite the above as:
(from p in nameList
where p.FirstName == "Pater"
select p).Apply(p => p.FirstName = "Peter");
Or (once you start using the lambda syntax go all the way):
nameList.Where(p => p.FirstName == "Pater").Apply(p => p.FirstName =
"Peter");
Michael M. Minutillo
Indiscriminate Information Sponge
Blog: http://wolfbyte-net.blogspot.com
On Fri, Feb 25, 2011 at 9:37 AM, Arjang Assadi <[email protected]>wrote:
> When using Linq to Objects, is it possible to change a property value
> on all the selected values?
> I am NOT using Linq to sql, I have list items and want to change value
> of some properties depending on names e.g.
>
> //typo in name entry, can not change the persisted data, instead
> correcting in code, there are no ID's to create a correction table for
> specific records, just having to hard code it heuristics.
>
> var names = from p in nameList
> where p.FirstName == "Pater"
> set p.FirstName = "Peter"
> select p;
>
> Regards
>
> Arjang
>