C#中的String.ToLowerInvariant()方法用于返回此String对象的副本,该副本使用不变区域性的大小写规则转换为小写形式。
语法如下-
public string ToLowerInvariant ();
现在让我们看一个例子-
using System; using System.Text; public class Demo { public static void Main(String[] args) { string str1 = "Pink Floyd"; string str2 = "Ariana"; Console.WriteLine("String 1 = "+str1); Console.WriteLine("String1 ToLowerInvariant = "+str1.ToLowerInvariant()); Console.WriteLine("String 2 = "+str2); Console.WriteLine("String2 ToLowerInvariant = "+str2.ToLowerInvariant()); Console.WriteLine("String 1 is equal to String 2: {0}", str1.Equals(str2)); } }
输出结果
String 1 = Pink Floyd String1 ToLowerInvariant = pink floyd String 2 = Ariana String2 ToLowerInvariant = ariana String 1 is equal to String 2: False
现在让我们来看另一个例子-
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 ToLowerInvariant = "+str1.ToLowerInvariant()); Console.WriteLine("String 2 = "+str2); Console.WriteLine("String2 ToLowerInvariant = "+str2.ToLowerInvariant()); Console.WriteLine("String 3 = "+str3); Console.WriteLine("String3 ToLowerInvariant = "+str3.ToLowerInvariant()); } }
输出结果
这将产生以下输出-
String 1 = one String1 ToLowerInvariant = one String 2 = TWO String2 ToLowerInvariant = two String 3 = ThrEE String3 ToLowerInvariant = three