C# Tutorial C# Advanced C# References

C# String - ToUpper() Method



The C# ToUpper() method returns the string with all characters of the specified string in uppercase. Any symbol, space, special character or number in the string is ignored while applying this method. Only Alphabets are converted.

Note: This method can be overloaded by passing different type of arguments to it.

Syntax

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

Parameters

culture Specify an object that supplies culture-specific casing rules.

Return Value

Returns the string with all characters of the specified string in uppercase.

Exception

Throws ArgumentNullException, if the culture is null.

Example:

In the example below, ToUpper() method returns a string containing all characters of the specified string MyStr in uppercase.

using System;

class MyProgram {
  static void Main(string[] args) {
    string MyStr = "HeLLo John!";
    string NewStr = MyStr.ToUpper();
 
    Console.WriteLine(NewStr); 
  }
}

The output of the above code will be:

HELLO JOHN!

Example:

In the example below, ToUpper() method returns a string containing all characters of the specified string MyStr in uppercase using the English-United States and Turkish-Turkey cultures.

using System;
using System.Globalization;
 
class MyProgram {
  static void Main(string[] args) {
    string MyStr = "HeLLo John!";
    string NewStr1 = MyStr.ToUpper(new CultureInfo("en-US", false));
    string NewStr2 = MyStr.ToUpper(new CultureInfo("tr-TR", false));

    Console.WriteLine(NewStr1); 
    Console.WriteLine(NewStr2);  
  }
}

The output of the above code will be:

HELLO JOHN!
HELLO JOHN!

❮ C# String Methods