.ToUpper()
Published Mar 22, 2023Updated Apr 7, 2023
Contribute to Docs
In C#, the .ToUpper()
method returns a new string with all the characters converted to uppercase. Numbers and symbols are not changed.
This method does not modify the original string, but instead, it creates a new string that contains the uppercase version of the original string.
Syntax
somestring.ToUpper()
This method will not change the input string.
Example
In the following example, originalString
is the string being converted to uppercase, and uppercaseString
is the new string that contains the uppercased characters. The original string remains unchanged:
using System;class Program{static void Main(string[] args){originalString = "Hello World"string uppercaseString = originalString.ToUpper();Console.WriteLine(originalString);Console.WriteLine(uppercaseString);}}
This will output:
Hello WorldHELLO WORLD
Codebyte Example
The example below converts a given string to uppercase and stores this value in a new string variable named uppercaseString
:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.