Advertisement
Fhernd

GenteEnumerator.cs

Aug 9th, 2017
14,718
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System.Collections;
  2. using System;
  3.  
  4. namespace cap07.usoienumerator
  5. {
  6.     public class GenteEnumerator : IEnumerator
  7.     {
  8.         public Persona[] personas;
  9.  
  10.         int position = -1;
  11.  
  12.         public GenteEnumerator(Persona[] personas)
  13.         {
  14.             this.personas = personas;
  15.         }
  16.  
  17.         public bool MoveNext()
  18.         {
  19.             ++position;
  20.             return (position < personas.Length);
  21.         }
  22.  
  23.         public void Reset()
  24.         {
  25.             position = -1;
  26.         }
  27.  
  28.         object IEnumerator.Current
  29.         {
  30.             get
  31.             {
  32.                 return Current;
  33.             }
  34.         }
  35.  
  36.         public Persona Current
  37.         {
  38.             get
  39.             {
  40.                 try
  41.                 {
  42.                     return personas[position];
  43.                 }
  44.                 catch (IndexOutOfRangeException)
  45.                 {
  46.                     throw new InvalidOperationException();
  47.                 }
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement