C# | String.ToUpperInvariant Method
String.ToUpperInvariant Method is used to get a copy of this String object converted to uppercase using the casing rules of the invariant culture. Here “invariant culture” represents a culture that is culture-insensitive.
Syntax:
public string ToUpperInvariant ();
Return Value: The return type of this method is System.String. This method will return a string which is the uppercase equivalent of the current string.
Below given are some examples to understand the implementation in a better way:
Example 1:
// C# program to illustrate // ToUpperInvariant() method using System; public class GFG { // Main method static public void Main() { // varibles string strA = "WelCome tO GeeKSfOrGeeKs"; string strB; // Convert strA into lowercase // using ToLowerInvariant() method strB = strA.ToUpperInvariant(); // Display string before ToUpperInvariant() method Console.WriteLine("String before ToUpperInvariant:"); Console.WriteLine(strA); Console.WriteLine(); // Display string after ToUpperInvariant() method Console.WriteLine("String after ToUpperInvariant:"); Console.WriteLine(strB); } } |
String before ToUpperInvariant: WelCome tO GeeKSfOrGeeKs String after ToUpperInvariant: WELCOME TO GEEKSFORGEEKS
Example 2:
// C# program to illustrate // ToUpperInvariant() Method using System; public class GFG { // Main method static public void Main() { // Calling function Convert("GEeks"); Convert("geeks"); Convert("GEEKS"); } static void Convert(String value) { // Display strings Console.WriteLine("string 1: {0}", value); // Convert sting into Uppercase // using ToUpperInvariant() method value = value.ToUpperInvariant(); // Display the Lowercase strings Console.WriteLine("string 2: {0}", value); } } |
string 1: GEeks string 2: GEEKS string 1: geeks string 2: GEEKS string 1: GEEKS string 2: GEEKS
Note:
- The invariant culture represents a culture that is culture-insensitive. It is associated with the English language but not with a specific country or region.
- ToUpperInvariant() method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to uppercase.
- This method can’t be overloaded if you try to overload this method, it will give you compile time error.
Reference: https://docs.microsoft.com/en-us/dotnet/api/system.string.toupperinvariant?view=netframework-4.7.2
Recommended Posts:
- Difference between Method Overriding and Method Hiding in C#
- C# | IndexOfAny() Method
- C# | Remove() Method
- C# | IsNullOrEmpty() Method
- C# | Replace() Method
- C# | Insert() Method
- C# | CopyTo() Method
- C# | Math.Tan() Method
- C# | Math.Cos() Method
- C# | Clone() Method
- C# | Math.Sin() Method
- C# | String.Contains() Method
- C# | Math.Log() Method
- C# | Math.Abs() Method | Set - 1
- C# | Uri.FromHex() Method
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



