In C#, ToUpper() is a string method. It converts every characters to uppercase (if there is an uppercase version). If a character does not have an uppercase equivalent, it remains unchanged. For example, special symbols remain unchanged. This method can be overloaded by passing different type of arguments to it.
String.ToUpper() Method
This method is used to returns a copy of the current string converted to uppercase. Syntax:
public string ToUpper();
Return Type: Its return the string value, which is the uppercase equivalent of the given string. The return type of this method is System.String. Example:
Input : str = "GeeksForGeeks"
str.ToUpper()
Output: GEEKSFORGEEKS
Input : str = "This is C# Program xsdd_$#%"
str.ToUpper()
Output: THIS IS C# PROGRAM XSDD_$#%
Below example programs illustrate the ToUpper() Method
csharp
using System;
class Program {
public static void Main()
{
string str1 = "GeeksForGeeks";
string upperstr1 = str1.ToUpper();
Console.WriteLine(upperstr1);
}
}
|
GEEKSFORGEEKS
csharp
using System;
class Program {
public static void Main()
{
string str2 = "This is C# Program xsdd_$#%";
string upperstr2 = str2.ToUpper();
Console.WriteLine(upperstr2);
}
}
|
THIS IS C# PROGRAM XSDD_$#%
String.ToUpper(CultureInfo) Method
This method is used to return a copy of the current string converted to uppercase, using the casing rules of the specified culture. Syntax:
public string ToUpper (System.Globalization.CultureInfo culture);
Parameter:
culture: It is the required object which supplies culture-specific casing rules.
Return Type: This method returns the uppercase equivalent of the current string of type System.String. Exception: This method can give ArgumentNullException if the value of culture is null. Example:
CSharp
using System;
using System.Globalization;
class Program {
public static void Main()
{
string str2 = "This is C# Program xsdd_$#%";
string upperstr2 = str2.ToUpper( new CultureInfo("en-US", false ));
Console.WriteLine(upperstr2);
}
}
|
Output:
THIS IS C# PROGRAM XSDD_$#%
Note: These methods will not modify the value of the current instance. Instead, these return a new string in which all characters in the current instance will convert to uppercase. Reference: https://docs.microsoft.com/en-us/dotnet/api/system.string.toupper?view=netframework-4.7.2
Last Updated :
08 Nov, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...