ForEach Support Inheriting From NameObjectCollectionBase HOW???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am writing custom collections for my business objects but I need support
for the foreach construct. I also need key support so I am inheriting from
NameObjectCollectionBase. I need to support foreach something like

e.g. foreach (HostSystem hs in myHost.Systems)

Unfortunately the builtin support for foreach only returns the keys of the
collection. Anyone have an sample code on how to accomplish this with each
of my custom collections.

Thanks
Mark
 
You can't really do what you want with the NameObjectCollection, so if you
need the NameObjectCollection, then you're going to have to use a different
loop structure than foreach.

If a plain array-style collection will meet your needs, then you can
implement a collection based on CollectionBase.

Pete
 
What about implementing IEnumerable and overriding the default
implementation? Can this not be done?
 
Back
Top