//C#通过ToUpper()方法将字符串转换成大写,代码如下: string sentence= "this is in upper case."; Console.WriteLine(sentence.ToUpper());
//C#通过ToLower()方法将字符串转换成小写,代码如下 string sentence= "this is in Lower case."; Console.WriteLine(sentence.ToLower());
//c#无视大小写对比字符串 //方法1. string s1 = "abcd"; string s2 = "ABCD"; if(s1.ToUpper()==s2.ToUpper()) { Console.WriteLine("在忽略大小写的情况下比较,这两个字符串相同"); } //方法2. if(s1.Equals(s2,StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("在忽略大小写的情况下比较,这两个字符串相同"); }