Back to notes -- Keyboard shortcut: 'u'  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    The class IntSingular.Lecture 8 - slide 26 : 37
Program 3
public class IntSingular: IntSequence{

  private int it;

  public IntSingular(int it){
    this.it = it;
  }

  public override int Min{
    get {return it;}
  }

  public override int Max{
    get {return it;}
  }

  public override IEnumerator GetEnumerator (){
    return new SingularEnumerator(this);
  }

  private class SingularEnumerator: IEnumerator{
 
    private readonly IntSingular ints; 
    private int idx;

    public SingularEnumerator (IntSingular ints){
      this.ints = ints;
      idx = -1;   // position enumerator outside range
    }
 
    public Object Current{ 
         get {return ints.it;}
    }

    public bool MoveNext (){
      if (idx == -1)
         {idx++; return true;}
      else
         {return false;}
    }

    public void Reset(){
      idx = -1;         
    }
  }
}