C# String ToUpper()

The String ToUpper() method converts all characters in the string to uppercase.

Example

using System;  
namespace CsharpString {  
  class Test {
    public static void Main(string [] args) {
     
      string str = "chocolate";
     
// converts str to upper case string result = str.ToUpper();
Console.WriteLine(result); Console.ReadLine(); } } } // Output: CHOCOLATE

ToUpper() Syntax

The syntax of the string ToUpper() method is:

ToUpper()

Here, ToUpper() is a method of class String.


ToUpper() Return Value

The ToUpper() method returns:

  • a copy of the string after converting it to uppercase

Example 1: C# String ToUpper()

using System;  
namespace CsharpString {  
  class Test {
    public static void Main(string [] args) {
     
      string str = "Ice Cream";
     
// converts str to upper case string result = str.ToUpper();
Console.WriteLine(result); Console.ReadLine(); } } }

Output

ICE CREAM

Here, str.ToUpper() converts the letters of str to uppercase.


ToUpper() With CultureInfo Parameter

We can also pass CultureInfo as an argument to the ToUpper() method. CultureInfo allows us to use the casing rules of the specified culture.

Its syntax is:

ToUpper(System.Globalization.CultureInfo culture)

Here,

culture - supplies culture-specific casing rules


Example 2: C# String ToUpper() With CultureInfo

using System;  
using System.Globalization;
namespace CsharpString {  
  class Test {
    public static void Main(string [] args) {
     
      string str = "ice cream";
     
// converts str to uppercase in Turkish-Turkey culture string result = str.ToUpper(new CultureInfo("tr-TR", false));
Console.WriteLine(result); Console.ReadLine(); } } }

Output

İCE CREAM

In the above program, notice the following code:

str.ToUpper(new CultureInfo("tr-TR", false))

Here, we have used the casing of Turkish-Turkey culture on str. This is given by the following CultureInfo() parameters:

  • tr-TR - uses Turkish-Turkey culture
  • false - denotes default culture settings

As a result, the lowercase "i" is converted to the Turkish "İ" instead of the US-English "I".

Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges