C# | String.ToLowerInvariant Method
String.ToLowerInvariant Method is used to get a copy of this String object converted to lowercase using the casing rules of the invariant culture. Here, “invariant culture” represents a culture that is culture-insensitive.
Syntax:
public string ToLowerInvariant ();
Return value: The return type of this method is System.String. This method returns a string which is a lowercase equivalent of the current string.
Below given are some examples to understand the implementation in a better way:
Example 1:
C#
// C# program to illustrate // ToLowerInvariant() method using System; class GFG { // Main method static public void Main() { // variables string strA = "WelCome tO w3wiki" ; string strB; // Convert strA into lowercase // using ToLowerInvariant() method strB = strA.ToLowerInvariant(); // Display string before ToLowerInvariant() method Console.WriteLine( "String before ToLowerInvariant:" ); Console.WriteLine(strA); Console.WriteLine(); // Display string after ToLowerInvariant() method Console.WriteLine( "String after ToLowerInvariant:" ); Console.WriteLine(strB); } } |
Output:
String before ToLowerInvariant: WelCome tO w3wiki String after ToLowerInvariant: welcome to w3wiki
Example 2:
C#
// C# program to illustrate // ToLowerInvariant() Method using System; public class GFG { // Main method static public void Main() { // calling function Convert( "GEeks" ); Convert( "Beginner" ); Convert( "Beginner" ); } static void Convert(String value) { // Display strings Console.WriteLine( "String 1: {0}" , value); // Convert string into Lowercase // using ToLowerInvariant() method value = value.ToLowerInvariant(); // Display the Lowercase strings Console.WriteLine( "String 2: {0}" , value); } } |
Output:
String 1: GEeks String 2: Beginner String 1: Beginner String 2: Beginner String 1: Beginner String 2: Beginner
Note:
- The invariant culture represents a culture that is culture-insensitive. It is associated with the English language but not with a specific country or region.
- ToLowerInvariant() method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to lowercase.
- This method can’t be overloaded if you try to overload this method, it will give you compile-time error.
Reference: https://docs.microsoft.com/en-us/dotnet/api/system.string.tolowerinvariant?view=netframework-4.7.2