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


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


CharEnumerator.GetType()方法用于获取当前实例的类型。此方法是从Object类继承的。

用法:

public Type GetType();

返回值:此方法返回当前实例的确切运行时类型。


下面的程序来说明CharEnumerator.GetType()方法的使用:+

示例1:

// C# program to illustrate the 
// use of CharEnumerator.GetType() 
// 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.GetType()); 
    } 
}
输出:
System.CharEnumerator

示例2:

// C# program to illustrate the 
// use of CharEnumerator.GetType() 
// Method 
using System; 
  
class GFG { 
  
    // Driver code 
    public static void Main() 
    { 
        // Initialize a string object 
        string str = "GeeksforGeeks is fun"; 
  
        // 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.GetType()); 
  
        Console.WriteLine("Type of CharEnumerator clone object: " 
                                        + chEnumClone.GetType()); 
    } 
}
输出:
Type of CharEnumerator object: System.CharEnumerator
Type of CharEnumerator clone object: System.CharEnumerator


相关用法


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