C# | ToUpper() Method

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

  • String.ToUpper() Method
  • String.ToUpper(CultureInfo) Method

String.ToUpper() Method

This method is used to returns a copy of the current string converted to uppercase.

Syntax:

public string ToUpper();

Return Type: Its return the string value, which is the uppercase equivalent of the given string. The return type of this method is System.String.

Example:

Input : str  = "GeeksForGeeks"
        str.ToUpper()
Output: GEEKSFORGEEKS

Input : str  = "This is C# Program xsdd_$#%"
        str.ToUpper()
Output: THIS IS C# PROGRAM XSDD_$#%

Below example programs illustrate the ToUpper() Method

  • Example 1:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

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

    chevron_right

    
    

    Output:

    GEEKSFORGEEKS
    
  • Example 2:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // C# program to desmonstrate the 
    // use of ToUpper() method 
    using System;
      
    class Program {
      
        // Main Method
        public static void Main()
        {
            // original string
            string str2 = "This is C# Program xsdd_$#%";
      
            // string converted to Upper case
            string upperstr2 = str2.ToUpper();
      
            Console.WriteLine(upperstr2);
        }
    }

    chevron_right

    
    

    Output:

    THIS IS C# PROGRAM XSDD_$#%
    

String.ToUpper(CultureInfo) Method

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

Syntax:

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

Parameter:

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

Return Type: This method returns the uppercase 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 ToUpper(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 Uppercase by
        // using English-United States culture
        string upperstr2 = str2.ToUpper(new CultureInfo("en-US", false));
  
        Console.WriteLine(upperstr2);
    }
}

chevron_right


Output:

THIS IS C# PROGRAM XSDD_$#%

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

Reference: https://docs.microsoft.com/en-us/dotnet/api/system.string.toupper?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.