-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathCharEnumerator.xml
540 lines (488 loc) · 39.9 KB
/
CharEnumerator.xml
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
<Type Name="CharEnumerator" FullName="System.CharEnumerator">
<TypeSignature Language="C#" Value="public sealed class CharEnumerator : ICloneable, System.Collections.Generic.IEnumerator<char>" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi sealed beforefieldinit CharEnumerator extends System.Object implements class System.Collections.Generic.IEnumerator`1<char>, class System.Collections.IEnumerator, class System.ICloneable, class System.IDisposable" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="DocId" Value="T:System.CharEnumerator" />
<TypeSignature Language="VB.NET" Value="Public NotInheritable Class CharEnumerator
Implements ICloneable, IEnumerator(Of Char)" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="F#" Value="type CharEnumerator = class
 interface IEnumerator<char>
 interface IEnumerator
 interface IDisposable
 interface ICloneable" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="C++ CLI" Value="public ref class CharEnumerator sealed : ICloneable, System::Collections::Generic::IEnumerator<char>" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<TypeSignature Language="C#" Value="public sealed class CharEnumerator : ICloneable, System.Collections.IEnumerator" FrameworkAlternate="netframework-1.1" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi serializable sealed beforefieldinit CharEnumerator extends System.Object implements class System.Collections.IEnumerator, class System.ICloneable" FrameworkAlternate="netframework-1.1" />
<TypeSignature Language="VB.NET" Value="Public NotInheritable Class CharEnumerator
Implements ICloneable, IEnumerator" FrameworkAlternate="netframework-1.1" />
<TypeSignature Language="F#" Value="type CharEnumerator = class
 interface IEnumerator
 interface ICloneable" FrameworkAlternate="netframework-1.1" />
<TypeSignature Language="C++ CLI" Value="public ref class CharEnumerator sealed : ICloneable, System::Collections::IEnumerator" FrameworkAlternate="netframework-1.1" />
<TypeSignature Language="ILAsm" Value=".class public auto ansi serializable sealed beforefieldinit CharEnumerator extends System.Object implements class System.Collections.Generic.IEnumerator`1<char>, class System.Collections.IEnumerator, class System.ICloneable, class System.IDisposable" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<TypeSignature Language="F#" Value="type CharEnumerator = class
 interface ICloneable
 interface IEnumerator<char>
 interface IDisposable
 interface IEnumerator" FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5" />
<TypeSignature Language="F#" Value="type CharEnumerator = class
 interface ICloneable
 interface IEnumerator<char>
 interface IEnumerator
 interface IDisposable" FrameworkAlternate="netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2" />
<TypeSignature Language="F#" Value="type CharEnumerator = class
 interface IEnumerator
 interface ICloneable
 interface IEnumerator<char>
 interface IDisposable" FrameworkAlternate="netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1" />
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<TypeForwardingChain>
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="5.0.0.0" FrameworkAlternate="net-5.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="6.0.0.0" FrameworkAlternate="net-6.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="7.0.0.0" FrameworkAlternate="net-7.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="8.0.0.0" FrameworkAlternate="net-8.0" />
<TypeForwarding From="netstandard" FromVersion="2.1.0.0" To="System.Runtime" ToVersion="9.0.0.0" FrameworkAlternate="net-9.0" />
</TypeForwardingChain>
<Base>
<BaseTypeName>System.Object</BaseTypeName>
</Base>
<Interfaces>
<Interface FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1">
<InterfaceName>System.Collections.Generic.IEnumerator<System.Char></InterfaceName>
</Interface>
<Interface>
<InterfaceName>System.Collections.IEnumerator</InterfaceName>
</Interface>
<Interface>
<InterfaceName>System.ICloneable</InterfaceName>
</Interface>
<Interface FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1">
<InterfaceName>System.IDisposable</InterfaceName>
</Interface>
</Interfaces>
<Attributes>
<Attribute FrameworkAlternate="netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<AttributeName Language="C#">[System.Serializable]</AttributeName>
<AttributeName Language="F#">[<System.Serializable>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1">
<AttributeName Language="C#">[System.Runtime.InteropServices.ComVisible(true)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.InteropServices.ComVisible(true)>]</AttributeName>
</Attribute>
</Attributes>
<Docs>
<summary>Supports iterating over a <see cref="T:System.String" /> object and reading its individual characters. This class cannot be inherited.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
A <xref:System.CharEnumerator> provides read-only access to the characters in a referenced <xref:System.String> object. For example, the `foreach` statement of the Microsoft Visual Basic and C# programming languages, which iterates through the elements of a collection, retrieves a <xref:System.CharEnumerator> from a <xref:System.String> object in order to iterate through the characters in that object.
> [!IMPORTANT]
> The `CharEnumerator` class enumerates individual 16-bit <xref:System.Char> instances. It does not consider graphemes (that is, a character followed by one or more combiding characters) or surrogate pairs (that is, characters outside the Unicode Basic Multilingual Plane) as single characters. For an enumerator that handles these types of characters as a single unit, use the <xref:System.Globalization.StringInfo> class.
There is no public constructor for <xref:System.CharEnumerator>. Instead, call a <xref:System.String> object's <xref:System.String.GetEnumerator%2A> method to obtain a <xref:System.CharEnumerator> that is initialized to reference the string.
A <xref:System.CharEnumerator> maintains an internal index to the characters in the string the <xref:System.CharEnumerator> references. The state of the index is invalid when it references a character position logically before the first character or after the last character in the string, and valid when it references a character within the string. The index is initialized to a position logically before the first character, and is set to a position after the last character when the iteration is complete. An exception is thrown if you attempt to access a character while the index is invalid.
The <xref:System.CharEnumerator.MoveNext%2A> method increments the index by one, so the first and subsequent characters are accessed in turn. The <xref:System.CharEnumerator.Reset%2A> method sets the index to a position logically before the first character. The <xref:System.CharEnumerator.Current%2A> property retrieves the character currently referenced by index. The <xref:System.CharEnumerator.Clone%2A> method creates a copy of the <xref:System.CharEnumerator>.
> [!NOTE]
> Several independent instances of <xref:System.CharEnumerator> across one or more threads can have access to a single instance of <xref:System.String>. This class is implemented to support the <xref:System.Collections.IEnumerator> interface. For more information regarding the use of an enumerator, see the <xref:System.Collections.IEnumerator> topic.
## Examples
The following example uses the <xref:System.CharEnumerator> class to enumerate the individual characters in a string. It instantiates a <xref:System.CharEnumerator> object by calling the <xref:System.String.GetEnumerator%2A?displayProperty=nameWithType> method, moves from one character to the next by calling the <xref:System.CharEnumerator.MoveNext%2A> method, and displays the current character by retrieving the value of the <xref:System.CharEnumerator.Current%2A> property.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1":::
Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet2":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2":::
]]></format>
</remarks>
<altmember cref="T:System.String" />
<altmember cref="T:System.Collections.IEnumerator" />
<altmember cref="T:System.Collections.IEnumerable" />
<altmember cref="T:System.Collections.ICollection" />
</Docs>
<Members>
<Member MemberName="Clone">
<MemberSignature Language="C#" Value="public object Clone ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance object Clone() cil managed" />
<MemberSignature Language="DocId" Value="M:System.CharEnumerator.Clone" />
<MemberSignature Language="VB.NET" Value="Public Function Clone () As Object" />
<MemberSignature Language="F#" Value="abstract member Clone : unit -> obj
override this.Clone : unit -> obj" Usage="charEnumerator.Clone " />
<MemberSignature Language="C++ CLI" Value="public:
 virtual System::Object ^ Clone();" />
<MemberType>Method</MemberType>
<Implements>
<InterfaceMember>M:System.ICloneable.Clone</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.NullableContext(1)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.NullableContext(1)>]</AttributeName>
</Attribute>
<Attribute FrameworkAlternate="netframework-4.0">
<AttributeName Language="C#">[System.Security.SecuritySafeCritical]</AttributeName>
<AttributeName Language="F#">[<System.Security.SecuritySafeCritical>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Object</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Creates a copy of the current <see cref="T:System.CharEnumerator" /> object.</summary>
<returns>An <see cref="T:System.Object" /> that is a copy of the current <see cref="T:System.CharEnumerator" /> object.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The return value is a copy of this instance of <xref:System.CharEnumerator> and its current state. This is useful for saving your state while iterating through a <xref:System.String> object.
For example, suppose your application uses an original instance of <xref:System.CharEnumerator> to iterate through each character in a <xref:System.String>. When some unique character is encountered, your application pauses processing and invokes the <xref:System.CharEnumerator.Clone%2A> method. In effect, this saves the <xref:System.CharEnumerator> object's index in the <xref:System.String>.
Your application uses the clone to navigate to another part of the `String` to perform some auxiliary processing. The side-effect of this navigation is the clone loses track of the position where processing stopped. However, when the auxiliary processing is complete, your application discards the clone and uses the original <xref:System.CharEnumerator> instance to resume working on the <xref:System.String> where the original processing stopped.
> [!NOTE]
> This method is implemented to support the <xref:System.ICloneable> interface.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Current">
<MemberSignature Language="C#" Value="public char Current { get; }" />
<MemberSignature Language="ILAsm" Value=".property instance char Current" />
<MemberSignature Language="DocId" Value="P:System.CharEnumerator.Current" />
<MemberSignature Language="VB.NET" Value="Public ReadOnly Property Current As Char" />
<MemberSignature Language="F#" Value="member this.Current : char" Usage="System.CharEnumerator.Current" />
<MemberSignature Language="C++ CLI" Value="public:
 property char Current { char get(); };" />
<MemberType>Property</MemberType>
<Implements>
<InterfaceMember FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-2.0;netcore-2.1;netcore-2.2;netcore-3.0;netcore-3.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1">P:System.Collections.Generic.IEnumerator`1.Current</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Char</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the currently referenced character in the string enumerated by this <see cref="T:System.CharEnumerator" /> object.</summary>
<value>The Unicode character currently referenced by this <see cref="T:System.CharEnumerator" /> object.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.CharEnumerator> class maintains an internal index to the enumerated string, and the <xref:System.CharEnumerator.Current%2A> property returns the character that is currently referenced by the index. This property should be invoked only when the index is valid; otherwise, an exception is thrown.
The index is always invalid for an empty string (""). The index is also invalid after the <xref:System.String.GetEnumerator%2A?displayProperty=nameWithType> or <xref:System.CharEnumerator.Reset%2A> method is called. After either of these methods is called, invoke the <xref:System.CharEnumerator.MoveNext%2A> method to adjust the index to the first character in the enumerated string. The index is valid whenever the <xref:System.CharEnumerator.MoveNext%2A> method returns `true`.
<xref:System.CharEnumerator.Current%2A> does not move the index, and consecutive calls to <xref:System.CharEnumerator.Current%2A> return the same character until <xref:System.CharEnumerator.MoveNext%2A>, <xref:System.CharEnumerator.Reset%2A>, or <xref:System.String.GetEnumerator%2A?displayProperty=nameWithType> is called.
## Examples
The following example uses the <xref:System.CharEnumerator> class to enumerate the individual characters in a string. It instantiates a <xref:System.CharEnumerator> object by calling the <xref:System.String.GetEnumerator%2A?displayProperty=nameWithType> method, moves from one character to the next by calling the <xref:System.CharEnumerator.MoveNext%2A> method, and displays the current character by retrieving the value of the <xref:System.CharEnumerator.Current%2A> property.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1":::
Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet2":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2":::
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">The index is invalid; that is, it is before the first or after the last character of the enumerated string.</exception>
</Docs>
</Member>
<Member MemberName="Dispose">
<MemberSignature Language="C#" Value="public void Dispose ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance void Dispose() cil managed" />
<MemberSignature Language="DocId" Value="M:System.CharEnumerator.Dispose" />
<MemberSignature Language="VB.NET" Value="Public Sub Dispose ()" />
<MemberSignature Language="F#" Value="abstract member Dispose : unit -> unit
override this.Dispose : unit -> unit" Usage="charEnumerator.Dispose " />
<MemberSignature Language="C++ CLI" Value="public:
 virtual void Dispose();" />
<MemberType>Method</MemberType>
<Implements>
<InterfaceMember>M:System.IDisposable.Dispose</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Releases all resources used by the current instance of the <see cref="T:System.CharEnumerator" /> class.</summary>
<remarks>
<format type="text/markdown">< and [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose).
> [!NOTE]
> Always call <xref:System.CharEnumerator.Dispose%2A> before you release your last reference to the <xref:System.CharEnumerator>. Otherwise, the resources it is using will not be freed until the garbage collector calls the <xref:System.CharEnumerator> object's `Finalize` method.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="MoveNext">
<MemberSignature Language="C#" Value="public bool MoveNext ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance bool MoveNext() cil managed" />
<MemberSignature Language="DocId" Value="M:System.CharEnumerator.MoveNext" />
<MemberSignature Language="VB.NET" Value="Public Function MoveNext () As Boolean" />
<MemberSignature Language="F#" Value="abstract member MoveNext : unit -> bool
override this.MoveNext : unit -> bool" Usage="charEnumerator.MoveNext " />
<MemberSignature Language="C++ CLI" Value="public:
 virtual bool MoveNext();" />
<MemberType>Method</MemberType>
<Implements>
<InterfaceMember>M:System.Collections.IEnumerator.MoveNext</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Boolean</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Increments the internal index of the current <see cref="T:System.CharEnumerator" /> object to the next character of the enumerated string.</summary>
<returns>
<see langword="true" /> if the index is successfully incremented and within the enumerated string; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.CharEnumerator> class maintains an internal index to the enumerated string, and the <xref:System.CharEnumerator.MoveNext%2A> method increments the index by one. Call <xref:System.CharEnumerator.MoveNext%2A> after calling <xref:System.String.GetEnumerator%2A> or <xref:System.CharEnumerator.Reset%2A> to increment the current character position to the first character in the enumerated string. Check that the return value is `true` to determine that the current character position is valid.
If the index is already beyond the last character of the enumerated string, the index is not changed and `false` is returned.
Notice that if the enumerated string is empty (""), the state of the <xref:System.CharEnumerator> is always invalid. This is because the internal index for the <xref:System.CharEnumerator> is initially before the first character of the enumerated string and is therefore invalid. <xref:System.CharEnumerator.MoveNext%2A> logically sets the index after the last (nonexistent) character of the enumerated string which is also invalid.
## Examples
The following example uses the <xref:System.CharEnumerator> class to enumerate the individual characters in a string. It instantiates a <xref:System.CharEnumerator> object by calling the <xref:System.String.GetEnumerator%2A?displayProperty=nameWithType> method, moves from one character to the next by calling the <xref:System.CharEnumerator.MoveNext%2A> method, and displays the current character by retrieving the value of the <xref:System.CharEnumerator.Current%2A> property.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet1":::
:::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet1":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1":::
Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows.
:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet2":::
:::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet2":::
:::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet2":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2":::
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="Reset">
<MemberSignature Language="C#" Value="public void Reset ();" />
<MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance void Reset() cil managed" />
<MemberSignature Language="DocId" Value="M:System.CharEnumerator.Reset" />
<MemberSignature Language="VB.NET" Value="Public Sub Reset ()" />
<MemberSignature Language="F#" Value="abstract member Reset : unit -> unit
override this.Reset : unit -> unit" Usage="charEnumerator.Reset " />
<MemberSignature Language="C++ CLI" Value="public:
 virtual void Reset();" />
<MemberType>Method</MemberType>
<Implements>
<InterfaceMember>M:System.Collections.IEnumerator.Reset</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Initializes the index to a position logically before the first character of the enumerated string.</summary>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
The <xref:System.CharEnumerator> class maintains an internal index to the enumerated string, and the <xref:System.CharEnumerator.Reset%2A> method sets the index to the invalid state.
]]></format>
</remarks>
</Docs>
</Member>
<Member MemberName="System.Collections.IEnumerator.Current">
<MemberSignature Language="C#" Value="object? System.Collections.IEnumerator.Current { get; }" FrameworkAlternate="net-5.0;net-6.0;net-7.0;net-8.0;net-9.0;netcore-3.0;netcore-3.1" />
<MemberSignature Language="ILAsm" Value=".property instance object System.Collections.IEnumerator.Current" />
<MemberSignature Language="DocId" Value="P:System.CharEnumerator.System#Collections#IEnumerator#Current" />
<MemberSignature Language="VB.NET" Value=" ReadOnly Property Current As Object Implements IEnumerator.Current" />
<MemberSignature Language="F#" Value="member this.System.Collections.IEnumerator.Current : obj" Usage="System.Collections.IEnumerator.Current" />
<MemberSignature Language="C++ CLI" Value="property System::Object ^ System::Collections::IEnumerator::Current { System::Object ^ get(); };" />
<MemberSignature Language="C#" Value="object System.Collections.IEnumerator.Current { get; }" FrameworkAlternate="netcore-2.0;netcore-2.1;netcore-2.2;netframework-1.1;netframework-2.0;netframework-3.0;netframework-3.5;netframework-4.0;netframework-4.5;netframework-4.5.1;netframework-4.5.2;netframework-4.6;netframework-4.6.1;netframework-4.6.2;netframework-4.7;netframework-4.7.1;netframework-4.7.2;netframework-4.8;netframework-4.8.1;netstandard-2.0;netstandard-2.1" />
<MemberType>Property</MemberType>
<Implements>
<InterfaceMember>P:System.Collections.IEnumerator.Current</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>1.0.5000.0</AssemblyVersion>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.5.0</AssemblyVersion>
<AssemblyVersion>4.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.1.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
<AssemblyVersion>4.2.0.0</AssemblyVersion>
<AssemblyVersion>4.2.1.0</AssemblyVersion>
<AssemblyVersion>4.2.2.0</AssemblyVersion>
<AssemblyVersion>5.0.0.0</AssemblyVersion>
<AssemblyVersion>6.0.0.0</AssemblyVersion>
<AssemblyVersion>7.0.0.0</AssemblyVersion>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<AssemblyVersion>9.0.0.0</AssemblyVersion>
</AssemblyInfo>
<Attributes>
<Attribute FrameworkAlternate="net-8.0;net-9.0">
<AttributeName Language="C#">[System.Runtime.CompilerServices.Nullable(2)]</AttributeName>
<AttributeName Language="F#">[<System.Runtime.CompilerServices.Nullable(2)>]</AttributeName>
</Attribute>
</Attributes>
<ReturnValue>
<ReturnType>System.Object</ReturnType>
</ReturnValue>
<Docs>
<summary>Gets the currently referenced character in the string enumerated by this <see cref="T:System.CharEnumerator" /> object. For a description of this member, see <see cref="P:System.Collections.IEnumerator.Current" />.</summary>
<value>The boxed Unicode character currently referenced by this <see cref="T:System.CharEnumerator" /> object.</value>
<remarks>
<format type="text/markdown"><![CDATA[
## Remarks
This member is an explicit interface member implementation. It can be used only when the <xref:System.CharEnumerator> instance is cast to an <xref:System.Collections.IEnumerator> interface.
]]></format>
</remarks>
<exception cref="T:System.InvalidOperationException">Enumeration has not started.
-or-
Enumeration has ended.</exception>
</Docs>
</Member>
<Member MemberName="System.IDisposable.Dispose">
<MemberSignature Language="C#" Value="void IDisposable.Dispose ();" />
<MemberSignature Language="ILAsm" Value=".method hidebysig newslot virtual instance void System.IDisposable.Dispose() cil managed" />
<MemberSignature Language="DocId" Value="M:System.CharEnumerator.System#IDisposable#Dispose" />
<MemberSignature Language="VB.NET" Value="Sub Dispose () Implements IDisposable.Dispose" />
<MemberSignature Language="F#" Value="abstract member System.IDisposable.Dispose : unit -> unit
override this.System.IDisposable.Dispose : unit -> unit" Usage="charEnumerator.System.IDisposable.Dispose " />
<MemberSignature Language="C++ CLI" Value=" virtual void System.IDisposable.Dispose() = IDisposable::Dispose;" />
<MemberType>Method</MemberType>
<Implements>
<InterfaceMember>M:System.IDisposable.Dispose</InterfaceMember>
</Implements>
<AssemblyInfo>
<AssemblyName>mscorlib</AssemblyName>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>System.Runtime</AssemblyName>
</AssemblyInfo>
<AssemblyInfo>
<AssemblyName>netstandard</AssemblyName>
</AssemblyInfo>
<ReturnValue>
<ReturnType>System.Void</ReturnType>
</ReturnValue>
<Parameters />
<Docs>
<summary>Releases all resources used by the <see cref="T:System.CharEnumerator" /> class.</summary>
<remarks>
<format type="text/markdown">< and [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose).
> [!NOTE]
> Always call IDisposable.Dispose before you release your last reference to the <xref:System.CharEnumerator> class. Otherwise, the resources it is using will not be freed until the garbage collector calls the <xref:System.CharEnumerator> object's <xref:System.Object.Finalize> method.
]]></format>
</remarks>
</Docs>
</Member>
</Members>
</Type>