C# String ToUpper() Method
The ToUpper()
method in C# is used to convert all the characters in a string to uppercase. It returns a new string with all the characters converted to uppercase.
The syntax of the ToUpper()
method is as follows:
string upperCaseString = string.ToUpper();
For example, to convert a string to uppercase, you can use the following code:
string text = "Hello World"; string upperCaseText = text.ToUpper(); Console.WriteLine(upperCaseText); // Output: "HELLO WORLD"
In this example, the ToUpper()
method is used to convert the string "Hello World" to uppercase. The resulting uppercase string "HELLO WORLD" is assigned to the upperCaseText
variable, which is then printed to the console using the WriteLine()
method.
Note that the ToUpper()
method does not modify the original string. Instead, it returns a new string with all the characters converted to uppercase. If you need to modify the original string, you can assign the result of the ToUpper()
method back to the original string variable.