C# | ToLower() Method

In C#, ToLower() is a string method. It converts every character to lowercase (if there is a lowercase character). If a character does not have a lowercase equivalent, it remains unchanged. For example, special symbols remain unchanged. This method can be overloaded by passing the different type of arguments to it.

  • String.ToLower() Method
  • String.ToLower(CultureInfo) Method

String.ToLower() Method

This method is used to return a copy of the current string converted to lowercase.

Syntax:

public string ToLower ();

Return Type: It return the string value, which is the lowercase equivalent of the string of type System.String.

Example:

Input : str  = "GeeksForGeeks"
        str.ToLower()
Output: geeksforgeeks

Input : str  = "This is C# Program xsdD_$#%"
        str.ToLower()
Output: this is c# program xsdd_$#%

Below Programs illustrate the use ToLower() Method:

  • Example 1:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // C# program to desmonstrate the 
    // use of ToLower() method 
    using System;
      
    class Program {
      
        // Main Method
        public static void Main()
        {
      
            // original string
            string str1 = "GeeksForGeeks";
      
            // string converted to lower case
            string lowerstr1 = str1.ToLower();
      
            Console.WriteLine(lowerstr1);
        }
    }

    chevron_right

    
    

    Output:

    geeksforgeeks
    
  • Example 2:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // C# program to desmonstrate the 
    // use of ToLower() method 
    using System;
      
    class Program {
      
        // Main Method
        public static void Main()
        {
      
            // original string containing the special
            // symbol. Here special symbol will remain 
            // unchange
            string str2 = "This is C# Program xsdD_$#%";
      
            // string converted to lower case
            string lowerstr2 = str2.ToLower();
      
            Console.WriteLine(lowerstr2);
        }
    }

    chevron_right

    
    

    Output:

    this is c# program xsdd_$#%
    

String.ToLower(CultureInfo) Method

This method is used to return a copy of the current string converted to lowercase, using the casing rules of the specified culture.

Syntax:

public string ToLower (System.Globalization.CultureInfo culture);

Parameter:

culture: It is the required object which supplies culture-specific casing rules.

Return Type: This method returns the lowercase equivalent of the current string of type System.String.

Exception: This method can give ArgumentNullException if the value of culture is null.

Example:

filter_none

edit
close

play_arrow

link
brightness_4
code

// C# program to desmonstrate the 
// use of ToLower(CultureInfo) method 
using System;
using System.Globalization;
  
class Program {
  
    // Main Method
    public static void Main()
    {
        // original string
        string str2 = "THIS IS C# PROGRAM XSDD_$#%";
  
        // string converted to lowercase by
        // using English-United States culture
        string lowerstr2 = str2.ToLower(new CultureInfo("en-US", false));
  
        Console.WriteLine(lowerstr2);
    }
}

chevron_right


Output:

this is c# program xsdd_$#%

Note: These methods will not modify the value of the current instance. Instead, returns a new string in which all characters in the current instance will convert to lowercase.

Reference: https://docs.microsoft.com/en-us/dotnet/api/system.string.tolower?view=netframework-4.7.2



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.