Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

C# | ToUpper() Method

  • Last Updated : 31 Jan, 2019

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:




    // 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);
        }
    }

    Output:

    GEEKSFORGEEKS
    
  • Example 2:




    // 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);
        }
    }

    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:




// 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);
    }
}

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
Recommended Articles
Page :