mscorlib(4.0.0.0) API with additions
CharEnumerator.cs
1 using System.Collections;
4 
5 namespace System
6 {
9  [ComVisible(true)]
11  {
12  private string str;
13 
14  private int index;
15 
16  private char currentElement;
17 
21  object IEnumerator.Current
22  {
23  get
24  {
25  if (index == -1)
26  {
27  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumNotStarted"));
28  }
29  if (index >= str.Length)
30  {
31  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumEnded"));
32  }
33  return currentElement;
34  }
35  }
36 
40  public char Current
41  {
42  get
43  {
44  if (index == -1)
45  {
46  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumNotStarted"));
47  }
48  if (index >= str.Length)
49  {
50  throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_EnumEnded"));
51  }
52  return currentElement;
53  }
54  }
55 
56  internal CharEnumerator(string str)
57  {
58  this.str = str;
59  index = -1;
60  }
61 
64  public object Clone()
65  {
66  return MemberwiseClone();
67  }
68 
72  public bool MoveNext()
73  {
74  if (index < str.Length - 1)
75  {
76  index++;
77  currentElement = str[index];
78  return true;
79  }
80  index = str.Length;
81  return false;
82  }
83 
85  public void Dispose()
86  {
87  if (str != null)
88  {
89  index = str.Length;
90  }
91  str = null;
92  }
93 
95  public void Reset()
96  {
97  currentElement = '\0';
98  index = -1;
99  }
100  }
101 }
object Clone()
Creates a copy of the current T:System.CharEnumerator object.
void Dispose()
Releases all resources used by the current instance of the T:System.CharEnumerator class.
Provides a mechanism for releasing unmanaged resources.To browse the .NET Framework source code for t...
Definition: IDisposable.cs:8
Definition: __Canon.cs:3
Supports iterating over a T:System.String object and reading its individual characters....
bool MoveNext()
Increments the internal index of the current T:System.CharEnumerator object to the next character of ...
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
void Reset()
Initializes the index to a position logically before the first character of the enumerated string.
object Current
Gets the element in the collection at the current position of the enumerator.
Definition: IEnumerator.cs:15
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
Definition: ICloneable.cs:7
Specifies that the class can be serialized.
The exception that is thrown when a method call is invalid for the object's current state.
Supports a simple iteration over a non-generic collection.
Definition: IEnumerator.cs:9