473,385 Members | 1,521 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

ForEach Support Inheriting From NameObjectCollectionBase HOW???

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
Nov 16 '05 #1
2 1968
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

"Mark Overstreet" <Ma************@discussions.microsoft.com> wrote in
message news:69**********************************@microsof t.com...
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

Nov 16 '05 #2
What about implementing IEnumerable and overriding the default
implementation? Can this not be done?

"Pete Davis" wrote:
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

"Mark Overstreet" <Ma************@discussions.microsoft.com> wrote in
message news:69**********************************@microsof t.com...
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


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: thechaosengine | last post by:
Hi all, I wanted to put some common security functions into a class that inherits from the Page class and then use the new class as the basis for all my pages. Unfortunately, if I try and...
1
by: Rein Petersen | last post by:
Hi Everyone! I hope someone may have experience serializing a NameObjectCollectionBase (System.Collections.Specialized) and can advise me as to why I receive this error (below) when I try to...
3
by: William Stacey [MVP] | last post by:
What is the deal with NameObjectCollectionBase? It allows duplication keys to be added to the hashtable using System; using System.Collections; using System.Collections.Specialized; ...
104
by: cody | last post by:
What about an enhancement of foreach loops which allows a syntax like that: foeach(int i in 1..10) { } // forward foeach(int i in 99..2) { } // backwards foeach(char c in 'a'..'z') { } // chars...
2
by: Shayne H | last post by:
I wanted to create a type-safe collection by inheriting from CollectionBase. Public Class MyCollection : Inherits CollectionBase I found that IList.Add did not allow the setting of a "key" to...
3
by: Sam Marrocco | last post by:
I've created a collection class that inherits the NameObjectCollectionBase. I'd like to add a few functions, such as being able to insert a new item at an indexed or keyed location in the...
2
by: Sam Marrocco | last post by:
I've created a collection class that inherits NameObjectCollectionBase (call it MyCollection). MyCollection is declared as serializable, and serializes fine. A cursory glance into the serialized...
11
by: Bit Byte | last post by:
I am writing a generic container class which I want to support the 'foreach' statement. My class looks something like this: class MyClass<T: CollectionBase { //Implementation for...
6
by: John A Grandy | last post by:
Is it possible to write a foreach so that it simultaneously iterates through two collections ( or two properties of the same collection ) ? Following is *only meant as an example* : -- iterate...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.