Javatpoint Logo
Javatpoint Logo

Char.ToLowerInvariant(Char) Method in C#

The Char.ToLowerInvariant(Char) function in C# uses the invariant culture to convert a specific Unicode character to its lowercase equivalent. It is a part of the Char class. This method is incredibly helpful when you want to manipulate characters without being affected by their cultural settings.

Syntax:

It has the following syntax:

Access Modifier:

public: The visibility of a method may be specified using the public access modifier. In this case, the method may be accessed from any other code within the same assembly and external assemblies.

Static Keyword :

static: Static indicates that the method belongs to the type rather than an instance of the type. In other words, you can call this method without creating an instance of the class that contains it.

Return Type:

char: Char is the data type of the value the method returns. In this case, the method returns a single Unicode character.

Method Name:

ToLowerInvariant: ToLowerInvariant is the name of the method. This method is intended for converting a Unicode character to its lowercase equivalent using the invariant culture.

Example 1:

Let us take an example to illustrate the Char.ToLowerInvariant(Char) method in C#.

Output:

Original Char is: S, Lowercase Char is: s
Original Char is: X, Lowercase Char is: x
Original Char is: 3, Lowercase Char is: 3
Original String is: HeLloWorlD, Lowercase String is: helloworld

Explanation:

1. Character Conversion:

original_Char1, original_Char2, and original_Char3 are declared and initialized with the characters 'S', 'X', and '3'.

After that, each of these characters is converted to lowercase using Char.ToLowerInvariant, the output is kept in lowercase_Char1, lowercase_Char2, and lowercase_Char3.

2. Displaying Results:

"Console.WriteLine" is used to display the character conversion results.

3. String Conversion:

Using "Char.ToLowerInvariant" for each character, ConvertToLowerCaseInvariant takes a string (input) as an argument and changes it to lowercase. The method returns the modified string.

4. Displaying String Results:

"Console.WriteLine" displays both the original and lowercase versions of the input string. The program demonstrates how to convert characters to their lowercase equivalents using Char.ToLowerInvariant, and applies this to both individual characters and an entire string.

Example 2:

Let us take another example to illustrate the Char.ToLowerInvariant(Char) method in C#.

Output:

The lowercase equivalent value of the Q is q
The lowercase equivalent value of the y is y
The lowercase equivalent value of the F is f
The lowercase equivalent value of the 6 is 6

Explanation:

1. Main Method:

The program's entry point is the Main method.

Using a different character as an argument, it makes four calls to the get method.

2. Get method:

The get method requires a char parameter called 'c'.

The lowercase equivalent of the input character 'c' is obtained within the method using the Char.ToLowerInvariant method.

The lowercase equivalent of the input character 'c' is obtained within the method using the Char.ToLowerInvariant method. This method uses the invariant culture's casing rules to convert a given Unicode character to its lowercase equivalent.

The lowercase character is stored in the variable 'ch'.

After that, a message is displayed to the console using "Console.WriteLine", showing the original character 'c' and its lowercase equivalent 'ch'.

3. Output:

'Q', 'y', 'F', and '6' are the four distinct characters that used when the Main method uses the get method four times.

The program displays a message for each call, including the original character and its lowercase equivalent.

The application shows how to convert characters to their lowercase equivalents using Char.ToLowerInvariant, and then prints the results for each character that is passed to the get method.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA