-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsersEnumerator.cs
52 lines (42 loc) · 1.05 KB
/
UsersEnumerator.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections;
using System.Collections.Generic;
namespace Enumeration
{
internal class UsersEnumerator : IEnumerator<User>
{
private readonly User[] _users;
private int _index = -1;
public UsersEnumerator(User[] users)
{
this._users = users;
}
public User Current { get; private set; }
object IEnumerator.Current => null;
public void Dispose()
{
// throw new NotImplementedException();
}
public bool MoveNext()
{
this._index++;
try
{
this.Current = this._users[_index];
return true;
}
catch (IndexOutOfRangeException e)
{
Console.WriteLine(e.Message);
this.Current = null;
this._index = -1;
}
return false;
}
public void Reset()
{
this._index = -1;
this.Current = null;
}
}
}