Created
August 10, 2017 04:37
-
-
Save Fhernd/5b0309d1ba0cb66c8f8401ff27559da0 to your computer and use it in GitHub Desktop.
Clase que implementa la interfaz IEnumerator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System; | |
namespace cap07.usoienumerator | |
{ | |
public class GenteEnumerator : IEnumerator | |
{ | |
public Persona[] personas; | |
int position = -1; | |
public GenteEnumerator(Persona[] personas) | |
{ | |
this.personas = personas; | |
} | |
public bool MoveNext() | |
{ | |
++position; | |
return (position < personas.Length); | |
} | |
public void Reset() | |
{ | |
position = -1; | |
} | |
object IEnumerator.Current | |
{ | |
get | |
{ | |
return Current; | |
} | |
} | |
public Persona Current | |
{ | |
get | |
{ | |
try | |
{ | |
return personas[position]; | |
} | |
catch (IndexOutOfRangeException) | |
{ | |
throw new InvalidOperationException(); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment