I made an extension which adds ForEach() method on ObservableCollection :
public static void ForEach<T>(this ObservableCollection<T> enumerable, Action<T> action)
{
foreach (var item in enumerable)
action(item);
}
When I use it, like this :
private bool Bar(int i)
{
return i % 2 == 1;
}
private void Foo()
{
Boolean ok = true;
ObservableCollection<int> oc = new ObservableCollection<int> { 1, 2, 3, 4 };
oc.ForEach(i => ok &= Bar(i));
//ok is now false
}
I don't understand how does the ok
Boolean take the value returned by the Bar()
method which is executed by action(item)
?