So I currently have an address book program (purposely basic as didn't fancy writing anything more fancy) so a module of an assessment being done (this is not school work).
I have to demonstrate polymorphism, encapsulation and inheritance in this module.
I was wondering if implementing IEnumerable counts as polymorphism as shown below?
public class AddressBookEnumerator : IEnumerator
{
#region IEnumerable Implementation
public Person[] Contacts;
int Position = -1;
public AddressBookEnumerator(Person[] ContactList)
{
Contacts = ContactList;
}
public bool MoveNext()
{
Position++;
return (Position < Contacts.Length);
}
public void Reset()
{
Position = -1;
}
object IEnumerator.Current
{
get
{
return Current;
}
}
public Person Current
{
get
{
try
{
return Contacts[Position];
}
catch (IndexOutOfRangeException)
{
throw new InvalidOperationException();
}
}
}
#endregion
}
I only wonder if it is because of inheriting the IEnumerator class and then creating new methods with different behaviour in for my specific class? Or am I just misunderstanding how IEnumerator works.