當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。