C# String.ToUpperInvariant Method


The String.ToUpperInvariant() method in C# is used to return a copy of this String object converted to uppercase using the casing rules of the invariant culture.

Syntax

The syntax is as follows -

public string ToUpperInvariant ();

Example

Let us now see an example -

 Live Demo

using System;
using System.Text;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "one";
      string str2 = "TWO";
      string str3 = "ThrEE";
      Console.WriteLine("String 1 = "+str1);
      Console.WriteLine("String1 ToUpperInvariant = "+str1.ToUpperInvariant());
      Console.WriteLine("String 2 = "+str2);
      Console.WriteLine("String2 ToUpperInvariant = "+str2.ToUpperInvariant());
      Console.WriteLine("String 3 = "+str3);
      Console.WriteLine("String3 ToUpperInvariant = "+str3.ToUpperInvariant());
   }
}

Output

String 1 = one
String1 ToUpperInvariant = ONE
String 2 = TWO
String2 ToUpperInvariant = TWO
String 3 = ThrEE
String3 ToUpperInvariant = THREE

Example

 Live Demo

using System;
public class Demo {
   public static void Main(String[] args) {
      string str1 = "abcd";
      string str2 = "PQRS";
      Console.WriteLine("String 1 = "+str1);
      Console.WriteLine("String1 ToUpperInvariant = "+str1.ToUpperInvariant());
      Console.WriteLine("String 2 = "+str2);
      Console.WriteLine("String2 ToUpperInvariant = "+str2.ToLowerInvariant());
   }
}

Output

String 1 = abcd
String1 ToUpperInvariant = ABCD
String 2 = PQRS
String2 ToUpperInvariant = pqrs
raja
Published on 03-Dec-2019 12:21:57
Advertisements