CharEnumerator.ToString() Method is used to get a string that represents the current object. It is inherited from the Object Class.
Syntax:
public virtual string ToString();
Return Value: This method returns a string which represents the current CharEnumerator object.
Below are the programs to illustrate the use of CharEnumerator.ToString() Method:
Example 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());
}
} |
Output:
System.String
Example 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());
}
} |
Output:
Type of CharEnumerator Object: System.String Type of CharEnumerator clone Object: System.String