Is there an alternative to a foreach statement?

I want to do foreach for each child in my app.config, but there is no open definition for "GetEnumerator" in System.ServiceModel.Configuration.CustomBindingCollectionElement. I would not ask if it was my own class, but this is System One. Is there something I can use instead of foreach to scroll through each child in a BindingsSection?

This is what I want to perform foreach on

BindingsSection bindingsSection = ConfigurationManager.GetSection("system.serviceModel/bindings") as BindingsSection;
+3
source share
2 answers

BindingCollectionsis this Listwhich has a method called ForEach, so you can do something like this:

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

You can use foreach, but you will skip its property BindingCollections, for example:

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

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

Source: https://habr.com/ru/post/1792181/


All Articles