473,498 Members | 310 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Which interface(s) do I need to iterate over objects

Hi
I want to create a rather simple object with a few string attributes
to hold some database user information such as:

public class UserInfo
{
//Basic user information for each user associated with a database.
private string sDbName;
private string sUserName;
.... other stuff....

public string dbName
{
get {...} set{ }
}
public string UserName
{ ........etc.etc....
}
......more stuff
}

There can be many UserInfo objects for each database.

Then, I was thinking another object , say dbUsers, that contains many
UserInfo objects. One dbUsers object for each database. (Maybe now, I
would not need to keep the dbName in the UserInfo object as all
UserInfo objects would always belong to some dbUsers object.
And finally, an object, say AllDbsAndUsers to hold all dbUser
objects.

I would create one dbUser object at a time, populate it with several
UserInfo objects, for a particular db, and then "add" it to the
AllDbsAndUsers object.

To use AllDbsAndUsers I would like to be able to "add" objects, get
objects based on db name, etc...
It will be handy in several situations to be able to use foreach loops
to run through one object, while processing the inner objects.

I am looking at IEnumerable, IEnumerator, IDictionary, DictionaryBase
and Hashtables. I really am not sure where to begin.
Is there also an Interface called Iterator?

What is the basic minimum needed any any object to be able to use a
foreach loop?
Are the requirements different if I want to have an "add" method?

Thanks

Jeff
"I'll get this sooner or later"
Jan 31 '06 #1
3 1443
Check out IList and also CollectionBase
You could always inherit from HashTable (my favourite)

There's a good example in MSDN help files that demonstrates all this.
Can't remember what its called though.
I think it used the "Widget" class....

Jan 31 '06 #2
The minimum requirement to use foreach over an object is that it implements
the IEnumerable inteface
http://msdn.microsoft.com/library/de...mberstopic.asp
You can find some foreach info at
http://msdn.microsoft.com/library/de...hstatement.asp

Sayed Ibrahim Hashimi
www.sedodream.com
"Jeff User" wrote:
Hi
I want to create a rather simple object with a few string attributes
to hold some database user information such as:

public class UserInfo
{
//Basic user information for each user associated with a database.
private string sDbName;
private string sUserName;
.... other stuff....

public string dbName
{
get {...} set{ }
}
public string UserName
{ ........etc.etc....
}
......more stuff
}

There can be many UserInfo objects for each database.

Then, I was thinking another object , say dbUsers, that contains many
UserInfo objects. One dbUsers object for each database. (Maybe now, I
would not need to keep the dbName in the UserInfo object as all
UserInfo objects would always belong to some dbUsers object.
And finally, an object, say AllDbsAndUsers to hold all dbUser
objects.

I would create one dbUser object at a time, populate it with several
UserInfo objects, for a particular db, and then "add" it to the
AllDbsAndUsers object.

To use AllDbsAndUsers I would like to be able to "add" objects, get
objects based on db name, etc...
It will be handy in several situations to be able to use foreach loops
to run through one object, while processing the inner objects.

I am looking at IEnumerable, IEnumerator, IDictionary, DictionaryBase
and Hashtables. I really am not sure where to begin.
Is there also an Interface called Iterator?

What is the basic minimum needed any any object to be able to use a
foreach loop?
Are the requirements different if I want to have an "add" method?

Thanks

Jeff
"I'll get this sooner or later"

Jan 31 '06 #3
Just a little correction.

The minimum requirements is the object to expose public GetEnumerator method
that returns object exposing all the methods in IEnumerator.
Implementing IEnumerable or IEnumerator is not a must.

However implementing these interfaces is a good idea beacuse it makes type's
documentation clearer and easier to understand. Not implementing the
interfaces on the other hand can be used to improve the performance in a
case of collection of value types.
--

Stoitcho Goutsev (100)
"Sayed Ibrahim Hashimi" <Sa*****************@discussions.microsoft.com>
wrote in message news:CF**********************************@microsof t.com...
The minimum requirement to use foreach over an object is that it
implements
the IEnumerable inteface
http://msdn.microsoft.com/library/de...mberstopic.asp
You can find some foreach info at
http://msdn.microsoft.com/library/de...hstatement.asp

Sayed Ibrahim Hashimi
www.sedodream.com
"Jeff User" wrote:
Hi
I want to create a rather simple object with a few string attributes
to hold some database user information such as:

public class UserInfo
{
//Basic user information for each user associated with a database.
private string sDbName;
private string sUserName;
.... other stuff....

public string dbName
{
get {...} set{ }
}
public string UserName
{ ........etc.etc....
}
......more stuff
}

There can be many UserInfo objects for each database.

Then, I was thinking another object , say dbUsers, that contains many
UserInfo objects. One dbUsers object for each database. (Maybe now, I
would not need to keep the dbName in the UserInfo object as all
UserInfo objects would always belong to some dbUsers object.
And finally, an object, say AllDbsAndUsers to hold all dbUser
objects.

I would create one dbUser object at a time, populate it with several
UserInfo objects, for a particular db, and then "add" it to the
AllDbsAndUsers object.

To use AllDbsAndUsers I would like to be able to "add" objects, get
objects based on db name, etc...
It will be handy in several situations to be able to use foreach loops
to run through one object, while processing the inner objects.

I am looking at IEnumerable, IEnumerator, IDictionary, DictionaryBase
and Hashtables. I really am not sure where to begin.
Is there also an Interface called Iterator?

What is the basic minimum needed any any object to be able to use a
foreach loop?
Are the requirements different if I want to have an "add" method?

Thanks

Jeff
"I'll get this sooner or later"

Jan 31 '06 #4

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

Similar topics

3
1841
by: Caleb Hattingh | last post by:
Hi all I saw it on a webpage a few days ago, can't seem to find it again. Tried a google search for "pypy needed translate C modules" but that didn't turn up what I was looking for. ...
3
1026
by: Helene Day | last post by:
I am trying to access the Word Objects from a .NET project. I have some sample from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vsto2003_ta/html/WordObject.asp and I...
1
1228
by: John Cho | last post by:
if i do a friend Testclass operator +(Test class &obj2); it is not correct because i need two objects?
1
2803
by: Lincoln Yeoh | last post by:
Hi, If I have a program listening on 0.0.0.0:(someport) on all interfaces, how do I know which network interface a broadcast packet is coming in on - assuming Linux and _many_ interfaces. And...
13
1299
by: jbraly | last post by:
I am BY NO MEANS a developer or a programmer... I just do tech purchases for a school system. A teacher wants about 20 licensse for the following program (He said he got this info from the...
2
1358
by: preport | last post by:
Hopefully someone can clarify some of this for me. I am confused on what classes I should implement if I want to utilize the List<>.BinarySearch() and Sort() My class currently looks like: ...
8
4454
by: Frank Callone | last post by:
Until now I programmed a lot with C++ and Java. Now I want (have) to do some programming with Visual Basic. Which software do I need for this ? Which is the best GUI development tool for Visual...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7163
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4586
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
651
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
287
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.