Skip to content

Instantly share code, notes, and snippets.

@Fhernd
Created August 10, 2017 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fhernd/5b0309d1ba0cb66c8f8401ff27559da0 to your computer and use it in GitHub Desktop.
Save Fhernd/5b0309d1ba0cb66c8f8401ff27559da0 to your computer and use it in GitHub Desktop.
Clase que implementa la interfaz IEnumerator.
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