Open In App

C# | CharEnumerator.ToString() Method

Last Updated : 30 Apr, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads