Andrew
Andrew

Reputation: 1989

Is there an alternative to a foreach statement?

I want to do a foreach on each child in my app.config but there is no public definition for 'GetEnumerator' in System.ServiceModel.Configuration.CustomBindingCollectionElement I would not ask if this were my own class, but it is a System one. Is there something I can use instead of the foreach to loop through each child in the BindingsSection?

This is what I want to perform the foreach on

BindingsSection bindingsSection = ConfigurationManager.GetSection("system.serviceModel/bindings") as BindingsSection;

Upvotes: 3

Views: 3633

Answers (2)

Øyvind Bråthen
Øyvind Bråthen

Reputation: 60694

BindingCollections is a List that has a method called ForEach, so you can do something like this:

bindingsSection.BindingCollections.ForEach( e => {do something here});

Upvotes: 3

BoltClock
BoltClock

Reputation: 723448

You can use foreach, but you loop through its BindingCollections property, like this:

BindingsSection bindingsSection = ConfigurationManager.GetSection("system.serviceModel/bindings") as BindingsSection;

foreach (BindingCollectionElement collection in bindingsSection.BindingCollections)
{
    // ...
}

Upvotes: 3

Related Questions