473,405 Members | 2,338 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,405 software developers and data experts.

enumerators

hi i have an arraylist that has doctor objects with various properties,
members and methods.

i want to enumerate this arraylist object.
but i dont understand how.
this is what i have done
ArrayList arrDoctors = Doctors.GetAllDoctors();
for (int cnt =0;cnt<1; cnt++)
{
Doctor p = (Doctor) arrDoctors[cnt];
Messagebox.show (p.Name);
//many other properties
}
what is the advantage of enumerators over what i have done?

and how do i implement them for my doctors array
Nov 16 '05 #1
5 1014
The only advantage is that you'll be using a foreach statement.
But you'll still have to cast the Current object to a Doctor.

In v 2.0 of the Framework, the generics are gonna make our lifes much easier
in cases like yours, but for now, you can't use 'em.
Cheers,
Branimir

--
Branimir Giurov
MCSD.NET, MCDBA, MCT
eAgility LLC
"juan" <ic***@hotmail.com> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
hi i have an arraylist that has doctor objects with various properties,
members and methods.

i want to enumerate this arraylist object.
but i dont understand how.
this is what i have done
ArrayList arrDoctors = Doctors.GetAllDoctors();
for (int cnt =0;cnt<1; cnt++)
{
Doctor p = (Doctor) arrDoctors[cnt];
Messagebox.show (p.Name);
//many other properties
}
what is the advantage of enumerators over what i have done?

and how do i implement them for my doctors array

Nov 16 '05 #2
Hi juan,

foreach (Doctor p in Doctors.GetAllDoctors())
{
Messagebox.show (p.Name);
}

The advantage is more readable code.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"juan" <ic***@hotmail.com> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
hi i have an arraylist that has doctor objects with various properties,
members and methods.

i want to enumerate this arraylist object.
but i dont understand how.
this is what i have done
ArrayList arrDoctors = Doctors.GetAllDoctors();
for (int cnt =0;cnt<1; cnt++)
{
Doctor p = (Doctor) arrDoctors[cnt];
Messagebox.show (p.Name);
//many other properties
}
what is the advantage of enumerators over what i have done?

and how do i implement them for my doctors array

Nov 16 '05 #3
but dont i have to derive a class from IEnumerable interface?
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:u9*************@TK2MSFTNGP10.phx.gbl...
Hi juan,

foreach (Doctor p in Doctors.GetAllDoctors())
{
Messagebox.show (p.Name);
}

The advantage is more readable code.

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

"juan" <ic***@hotmail.com> wrote in message
news:er**************@TK2MSFTNGP09.phx.gbl...
hi i have an arraylist that has doctor objects with various properties,
members and methods.

i want to enumerate this arraylist object.
but i dont understand how.
this is what i have done
ArrayList arrDoctors = Doctors.GetAllDoctors();
for (int cnt =0;cnt<1; cnt++)
{
Doctor p = (Doctor) arrDoctors[cnt];
Messagebox.show (p.Name);
//many other properties
}
what is the advantage of enumerators over what i have done?

and how do i implement them for my doctors array


Nov 16 '05 #4
juan <ic***@hotmail.com> wrote:
but dont i have to derive a class from IEnumerable interface?


Doctors itself doesn't have to - Doctors.GetAllDoctors() returns an
ArrayList, and *that* can be enumerated.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5
Hi Juan,

You can directly enumerate an "ArrayList" with *foreach* construct.

You will get the advantage of enumerator when you implement
*IEnumerator* and *IEnumerable* interfaces in your "Doctors"
collection class.

In which case you will not be required to populate an extra ArrayList
but can directly enumerate the "Doctors" using *foreach* construct.
public interface IEnumerable {
IEnumerator GetEnumerator();
}

public interface IEnumerator {
Boolean MoveNext();
Object Current { get; }
void Reset();
}

You can check these links for more info:
http://www.codeguru.com/Csharp/Cshar...icle.php/c5505
http://msdn.microsoft.com/library/de...spec_9_3_1.asp
Hope it will help.

--
Cheers,
Rahul Anand
"juan" <ic***@hotmail.com> wrote in message news:<er**************@TK2MSFTNGP09.phx.gbl>...
hi i have an arraylist that has doctor objects with various properties,
members and methods.

i want to enumerate this arraylist object.
but i dont understand how.
this is what i have done
ArrayList arrDoctors = Doctors.GetAllDoctors();
for (int cnt =0;cnt<1; cnt++)
{
Doctor p = (Doctor) arrDoctors[cnt];
Messagebox.show (p.Name);
//many other properties
}
what is the advantage of enumerators over what i have done?

and how do i implement them for my doctors array

Nov 16 '05 #6

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

Similar topics

2
by: Bob Shafer | last post by:
Is it possible to create dynamic enumerators in Visual Basic .Net? For example, an enumurator that provides a dropdown of available SQL servers?
6
by: Matt Taylor | last post by:
I'm trying to write an x86 assembler in C++ for use in a debugger. What I'd like do is to use template specialization to prevent invalid combinations from compiling. Thus one could not accidentally...
1
by: Dave | last post by:
I have several enums that are generated by a code generator (and I have no control over the code generator), the problem is that the names are pretty long enum VeryLoooooooongEnumName {...
2
by: Peter Rilling | last post by:
A design pattern question. As you know, an enumerator in .NET is broken into two interface (IEnumerable and IEnumerator). Is there a benefit in having two interfaces? Why not just have the...
2
by: Andrew Quine | last post by:
Hi Short one: looking for a good example and an explanation of such enumerators. I know MessageEnumerator and ResourceReader do this, for example, but what is the implementation of the...
5
by: juan | last post by:
hi i have an arraylist that has doctor objects with various properties, members and methods. i want to enumerate this arraylist object. but i dont understand how. this is what i have done ...
6
by: Tim Davis | last post by:
I am currently writing a class which I would like to make "enumerable" by inheriting from IEnumerable. The documentation says that the IEnumerator.MoveNext method should throw an exception if the...
2
by: psbasha | last post by:
Hi , Does Python supports enumerators? enum{ Red=1, Gren, Blue, Orange}
1
muaddubby
by: muaddubby | last post by:
Hello all and happy new year. I've seen several posts floating around asking about string enumerators in C#, and generally speaking, they're not supported. I've come up with a way around it...
1
nitindel
by: nitindel | last post by:
Hi All, May i have an in depth article of enumerators in C#..that explains the Enumerators in C# very precisely.... Thanks, Nitin
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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,...
0
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...

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.