473,756 Members | 3,566 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 1457
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************ *****@discussio ns.microsoft.co m>
wrote in message news:CF******** *************** ***********@mic rosoft.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
1856
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. Anyone have that page ref handy listing the C modules that the pypy team need translated into python?
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 have MS Office 2003. However I don't know which file I need to reference for the MS Word 11.0 Object Library. Or what else do I need to install/download from MS to be able to create MS Office 2003 Projects.
1
1241
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
2818
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 how do I set which interface a frame will leave on, assuming I'm sending a raw frame (no IP address, just the ethernet address). If I use C, it seems I'm to use the IP_PKTINFO socket options, send/recv the ancillary messages and set/check the ...
13
1321
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 'About' screen info): Microsoft Visual Basic.Net Microsoft. Net Framework 1.1.4322 SP1
2
1371
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: public class MyClass : IComparable, IComparer, IEquatable<MyClass> What do I NEED to implement? I am consused looking at the documentation. It says that my class needs to implement IComparer<T> or IComparable<T>???
8
4475
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 Basic? When I search through Google it seems to me that most of the introduction think that Visual Basic is pre-installed. But I did not found a Visual Basic compiler on my Win2000 system. Where can I download the VisualBasic environment for...
0
9275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10034
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9872
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9713
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8713
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5142
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3805
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.