> I have a situation where I'd like to use a lambda, but I'm not sure how.
> Basically, I have a collection of objects and I want to set a property on
[quoted text clipped - 11 lines]
> I'm thinking that I can replace the foreach bit with a single lambda
> expression. Can anyone help me with that syntax?
Well, if you use List<T> instead, you can use List.ForEach.
Alternatively, you could (somewhat evilly) do:
var codes = from variable.VariableCodeList
where c.Type=="MyCondition"
select { c.IsShown=true; return c; } ;
(In other words, make the change part of the projection.)
Or you could write a ForEach extension method yourself - it would be
trivial to do.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Paul Prewett - 07 Mar 2008 17:19 GMT
Hm, yes.
Well, VariableCodeList is actually a List<T>, but once I do the Where(), I
am stuck with IEnumerable<T>.
I'm thinking I'll just leave it the way that it is.
Thanks for the input, though.

Signature
-Paul Prewett
> > I have a situation where I'd like to use a lambda, but I'm not sure how.
> > Basically, I have a collection of objects and I want to set a property on
[quoted text clipped - 24 lines]
> Or you could write a ForEach extension method yourself - it would be
> trivial to do.
Jon Skeet [C# MVP] - 07 Mar 2008 17:40 GMT
> Well, VariableCodeList is actually a List<T>, but once I do the Where(), I
> am stuck with IEnumerable<T>.
You can always call ToList() to get another List if you want.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Paul Prewett - 07 Mar 2008 18:47 GMT
Ah. There we go.
Thankee, sai.

Signature
-Paul Prewett
> > Well, VariableCodeList is actually a List<T>, but once I do the Where(), I
> > am stuck with IEnumerable<T>.
>
> You can always call ToList() to get another List if you want.