In this article, we will discuss the Char.ToUpperInvariant(Char) method in C# with syntax and examples.
What is the Char.ToUpperInvariant Method?
The Char.ToUpperInvariant method uilizes traditionally invariant formatting rules to convert the value of a Unicode character to its uppercase equivalent.
The character you want to convert to uppercase is the only parameter this method needs, which returns the uppercase equivalent of that character according to the rules of the language.
Syntax:
It has the following syntax:
public static char ToUpperInvariant ( char c )
where c is the Unicode character to convert.
Return Value:
The return value of the function is,
- When c is already uppercase or not alphabetic, the value of c remains unchanged.
- If not, the uppercase equivalent of the c parameter will be returned.
Program 1:
Let us take an example to illustrate the Char.ToUpperInvariant method in C#.
using System;
class ABC {
public static void Main()
{
// calling get() Method
get('P');
get('p');
get('Q');
get('q');
get('-');
}
public static void get(char c)
{
// getting Unicode character by using the ToUpperInvariant() Method
char val = Char.ToUpperInvariant(c);
// shows the char value
Console.WriteLine("The uppercase equivalent"+
" of the {0} is {1}", c, val);
}
}
Output:
Program 2:
Let us take another example to illustrate the Char.ToUpperInvariant method in C#.
using System;
using System.Globalization;
public class Example
{
public static void Main()
{
Char[] chars = {'a', 'A', 'b', 'B' };
foreach (var ch in chars) {
Console.Write(Char.ToUpperInvariant(ch));
}
}
}
Output: