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