Phương thức CharEnumerator.Reset() trong C# khởi tạo chỉ số (index) về vị trí logic trước ký tự đầu tiên của chuỗi được liệt kê.
Cú pháp
public void Reset();
Ví dụ
using System;
public class Demo {
public static void Main() {
string strNum = "This is it!";
CharEnumerator ch = strNum.GetEnumerator();
Console.WriteLine("HashCode = " + ch.GetHashCode());
Console.WriteLine("Lấy Type = " + ch.GetType());
while (ch.MoveNext())
Console.Write(ch.Current + " ");
ch.Reset();
Console.WriteLine();
while (ch.MoveNext())
Console.Write(ch.Current);
}
}
Kết quả
HashCode = 65311716 Lấy Type = System.CharEnumerator T h i s i s i t ! This is it!