C# 中的 Char.ToUpperInvariant(Char) 方法
csharpprogrammingserver side programming更新于 2025/9/20 7:03:00
C# 中的 Char.ToUpperInvariant() 方法用于使用不变文化的大小写规则将 Unicode 字符的值转换为其大写等价物。
语法
public static char ToUpperInvariant (char ch);
上面,参数 ch 是要转换的 Unicode 字符。
现在让我们看一个实现 Char.ToUpperInvariant() 方法的示例 −
示例
using System;
public class Demo {
public static void Main(){
char ch = 'q';
char res = Char.ToUpperInvariant(ch);
Console.WriteLine("Value = "+ch);
Console.WriteLine("Uppercase Equivalent = "+res);
}
}
输出
这将产生以下输出 −
Value = q Uppercase Equivalent = Q
现在让我们看另一个例子 −
示例
using System;
public class Demo {
public static void Main(){
char ch = 'r';
char res = Char.ToUpperInvariant(ch);
Console.WriteLine("Value = "+ch);
Console.WriteLine("Uppercase Equivalent = "+res);
}
}
输出
这将产生以下输出 −
Value = r Uppercase Equivalent = R

