📜  C#| Char.ToUpperInvariant(Char)方法

📅  最后修改于: 2021-05-29 23:22:48             🧑  作者: Mango

此方法用于使用不变区域性的大小写规则将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

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.char.toupperinvariant?view=netframework-4.7.2