I implemented ExtensionMethod, which basically works like ForEach-Loop, my implementation looks like this:
public static void ForEach(this ListItemCollection collection, Action<ListItem> act ) { foreach (ListItem item in collection) act(item); }
However, I would like the method to stop the loop after the first fulfillment of a certain condition.
Here's how I use it now:
ddlProcesses.Items.ForEach(item => item.Selected = item.Value == Request["Process"]?true:false);
The problem is that there can only be one element inside DropDownList that meets this requirement, but the loop is still finished, what would be the least ugly way to solve this problem?
Thanks.
source share