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


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


此方法用于使用不变区域性的大小写规则将Unicode字符的值转换为等效的大写形式。

用法:

public static char ToUpperInvariant (char c);

在这里,c是要转换的Unicode字符。


返回值:如果c已经是大写或不是字母,则此方法返回c参数的大写等效项或c的不变值。

以下示例程序旨在说明Char.ToUpperInvariant(Char)方法的用法:

示例1:

// C# program to demonstrate 
// Char.ToUpperInvariant() 
// Method 
using System; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
        // calling get() Method 
        get('A'); 
        get('a'); 
        get('B'); 
        get('b'); 
        get('-'); 
    } 
  
    // Defining get() method 
    public static void get(char c) 
    { 
  
        // getting Unicode character 
        // using ToUpperInvariant() Method 
        char val = Char.ToUpperInvariant(c); 
  
        // display the char value 
        Console.WriteLine("The uppercase equivalent"+ 
                      " of the {0} is {1}", c, val); 
    } 
}
输出:
The uppercase equivalent of the A is A
The uppercase equivalent of the a is A
The uppercase equivalent of the B is B
The uppercase equivalent of the b is B
The uppercase equivalent of the - is -

示例2:

// C# program to demonstrate 
// Char.ToUpperInvariant() 
// Method 
using System; 
  
class GFG { 
  
    // Main Method 
    public static void Main() 
    { 
        // declaring and intializing char variable 
        char c = 'a'; 
  
        // getting Unicode character 
        // using ToUpperInvariant() Method 
        char val = Char.ToUpperInvariant(c); 
  
        // display the char value 
        Console.WriteLine("The Uppercase equivalent"+ 
                       " of the {0} is {1}", c, val); 
    } 
}
输出:
The Uppercase equivalent of the a is A

参考:



相关用法


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