I am new to enumerating collections so forgive if this question sounds silly.
I have an class
public class PersonStuff : IPersonStuff, IEnumerable<User>
{
Person person = new Person();
...
IEnumerator<Person> IEnumerable<Person>.GetEnumerator()
{
return (person as IEnumerable<Person>).GetEnumerator();
}
}
As you can see, I am implementing two interfaces in the above: one being IPersonStuff and the other being IEnumerable.
The Person class is a simple getter/setter each type being of string e.g. name, address except dateofbirth which is DateTime.
And in my IPersonStuff I have this:
interface IPersonStuff
{
...
IEnumerator<Person> IEnumerable<Person>.GetEnumerator();
}
Once working, I would like to call it in the following manner (from any class):
IPersonStuff personStuff = new PersonStuff();
foreach (Person u in personStuff)
{
//this loop should iterate thru the elements.
}
However, I get the following error:
- 'IEnumerable<...>.GetEnumerator': explicit interface declaration can only be declared in a class or struct
Basically I want to know how is it possible to call the IEnumerator IEnumerable.GetEnumerator() I have in the PersonStuff class through the IPersonStuff Interface.