当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# CharEnumerator.ToString()用法及代码示例


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


相关用法


注:本文由纯净天空筛选整理自rupesh_rao大神的英文原创作品 C# | CharEnumerator.ToString() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。