C#中的CharEnumerator.MoveNext()方法

C#中的CharEnumerator.MoveNext()方法用于将当前CharEnumerator对象的内部索引递增到枚举字符串的下一个字符。

语法

public bool MoveNext ();

现在让我们看一个实现CharEnumerator.MoveNext()方法的示例-

示例

using System;
public class Demo {
   public static void Main(){
      string strNum = "john";
      CharEnumerator ch = strNum.GetEnumerator();
      Console.WriteLine("HashCode = "+ch.GetHashCode());
      Console.WriteLine("Get the Type = "+ch.GetType());
      while (ch.MoveNext())
         Console.Write(ch.Current + " ");
      //处置
      ch.Dispose();
      // this will show an error since we处置 the object above
      //Console.WriteLine(ch.Current); 
   }
}

输出结果

这将产生以下输出-

HashCode = 1373506
Get the Type = System.CharEnumerator
j o h n