CharEnumerator.Reset方法用于将索引初始化为逻辑上在枚举字符串的第一个字符之前的位置。
用法:
public void Reset ();
以下示例程序旨在说明CharEnumerator.Reset()方法的使用:
示例1:
// C# program to illustrate the
// use of CharEnumerator.Reset()
// Method
using System;
class GFG {
// Driver code
public static void Main()
{
// Initialize a string object
string str = "The Sun rises in the East and sets in the West.";
// Instantiate a CharEnumerator object
CharEnumerator chEnum = str.GetEnumerator();
// Printing the string
while (chEnum.MoveNext())
Console.Write(chEnum.Current);
// Reset the CharEnumerator object
chEnum.Reset();
Console.WriteLine();
// Printing the string again
while (chEnum.MoveNext())
Console.Write(chEnum.Current);
}
}
输出:
The Sun rises in the East and sets in the West. The Sun rises in the East and sets in the West.
示例2:
// C# program to illustrate the
// use of CharEnumerator.Reset()
// Method
using System;
class GFG {
// Driver code
public static void Main()
{
// Initialize a string object
string str = "0 1 2 3 4 5 6 7 8 9";
// Instantiate a CharEnumerator object
CharEnumerator chEnum = str.GetEnumerator();
// Printing the string
while (chEnum.MoveNext())
Console.Write(chEnum.Current);
// Reset the CharEnumerator object
chEnum.Reset();
Console.WriteLine();
// Printing the string again
while (chEnum.MoveNext())
Console.Write(chEnum.Current);
}
}
输出:
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9
参考:
相关用法
- C# DateTimeOffset.Add()用法及代码示例
- C# String.Contains()用法及代码示例
- C# Math.Sin()用法及代码示例
- C# Math.Cos()用法及代码示例
- C# Dictionary.Add()用法及代码示例
- C# Math.Tan()用法及代码示例
- C# Math.Abs()方法用法及代码示例
- C# Math.Exp()用法及代码示例
- C# Math.Abs()函数用法及代码示例
注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 C# | CharEnumerator.Reset() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。