C# .ToUpper()
Published Mar 22, 2023Updated Apr 7, 2023
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:
Learn C# on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn Microsoft's popular C# programming language, used to make websites, mobile apps, video games, VR, and more.
- Beginner Friendly.15 hours