CharEnumerator.ToString()方法用于获取表示当前对象的字符串。它是从对象类继承的。
句法:
public virtual string ToString();
返回值:该方法返回代表当前CharEnumerator对象的字符串。
下面的程序说明了CharEnumerator.ToString()方法的用法:
范例1:
// C# program to illustrate the
// use of CharEnumerator.ToString()
// Method
using System;
class GFG {
// Driver code
public static void Main()
{
// Initialize a string object
string str = "GeeksforGeeks is Awesome!!";
// Instantiate a CharEnumerator object
CharEnumerator chEnum = str.GetEnumerator();
// Printing the Type of
// the CharEnumerator objects
Console.WriteLine(chEnum.ToString().GetType());
}
}
输出:
System.String
范例2:
// C# program to illustrate the
// use of CharEnumerator.ToString()
// Method
using System;
class GFG {
// Driver code
public static void Main()
{
// Initialize a string object
string str = "GeeksforGeeks Ranking - 50!";
// Instantiate a CharEnumerator object
CharEnumerator chEnum = str.GetEnumerator();
// Instantiate a clone of CharEnumerator object
CharEnumerator chEnumClone = (CharEnumerator)chEnum.Clone();
// Printing the Type of the
// CharEnumerator objects
// and its clone
Console.WriteLine("Type of CharEnumerator Object: " +
chEnum.ToString().GetType());
Console.WriteLine("Type of CharEnumerator clone Object: " +
chEnumClone.ToString().GetType());
}
}
输出:
Type of CharEnumerator Object: System.String
Type of CharEnumerator clone Object: System.String