I implemented an ExtensionMethod which basically works as 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'd like the method to stop looping after the first time a specific condition is met.
Here's how I currently use it:
ddlProcesses.Items.ForEach(item => item.Selected = item.Value == Request["Process"]?true:false);
The Problem with this is that there can only be one item inside the DropDownList which matches this requirement, but the loop is being finished anyway, what would be the least ugly way to solve this problem?
Thanks.