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


C# Char.GetTypeCode()用法及代码示例


此方法用于返回值类型Char的TypeCode。

用法:

public TypeCode GetTypeCode ();

返回值:此方法返回枚举常量Char。


以下程序说明了Char.GetTypeCode()方法的使用:

示例1:

// C# program to demonstrate 
// Char.GetTypeCode() Method 
using System; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // Declaring val1 and val2 
        char val1; 
        bool val2; 
  
        // intializing the 
        // val1 and val2 
        val1 = 'A'; 
        val2 = true; 
  
        // getting TypeCode 
        // using GetTypeCode() method 
        TypeCode t1 = val1.GetTypeCode(); 
        TypeCode t2 = val2.GetTypeCode(); 
  
        // Display TypeCode 
        Console.WriteLine("TypeCode of val1 is {0}", t1); 
        Console.WriteLine("TypeCode of val2 is {0}", t2); 
    } 
}
输出:
TypeCode of val1 is Char
TypeCode of val2 is Boolean

示例2:

// C# program to demonstrate 
// Char.GetTypeCode() Method 
using System; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
  
        // Declaring val1 and val2 
        char val1; 
        float val2; 
  
        // intializing the 
        // val1 and val2 
        val1 = 'a'; 
        val2 = 20f; 
  
        // calling get() method 
        get(val1); 
        get(val2); 
    } 
  
    // Defining the get() method 
    public static void get(char val) 
    { 
  
        // getting TypeCode 
        // using GetTypeCode() method 
        TypeCode t = val.GetTypeCode(); 
  
        // Display the TypeCode 
        Console.WriteLine("TypeCode of {0} is {1}", 
                                          val, t); 
    } 
  
    public static void get(float val) 
    { 
  
        // getting TypeCode 
        // using GetTypeCode() method 
        TypeCode t = val.GetTypeCode(); 
  
        // Display the TypeCode 
        Console.WriteLine("TypeCode of {0} is {1}", 
                                            val, t); 
    } 
}
输出:
TypeCode of a is Char
TypeCode of 20 is Single

参考:



相关用法


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