Greetings,
I’m looking for a way to convert
foreach (var sEvent in Events)
{
sEvent.SomeId = 0;
}
to
Events.Set(m=>m.SomeId, 0);
or something like this.
So basicly I want to make it a one line event that sets all “SomeId” to 0;
Is there any way?
If
Eventsis aList<T>you can use:If
EventsisIEnumerable,ForEachis not implemented, but you can of course make your own ForEach that works onIEnumerableyourself. The reasonForEachis not created forIEnumerable, is that they did not want to have extension method onIEnumerablewith side effects (that altered the original collection).Implementing ForEach on IEnumerable is easy enough:
This has to go into a
staticclass just like all other extension methods.