c#学习第二天
今天继续看MSDN, 不经意间却发现了下面这段代码,测试了下,没想到微软的工程师也有不小心的时候
字符串对象也有一个 CompareTo() 方法,它根据一个字符串小于 (<)、等于 (==) 还是大于 (>) 另一个字符串而返回一个整数值。比较字符串时使用 Unicode 值,并且小写字母的值小于大写字母的值。有关比较字符串的规则的更多信息,请参见
C# | |
---|---|
// Enter different values for string1 and string2 to // experiement with behavior of CompareTo string string1 = "ABC"; string string2 = "abc"; int result = string1.CompareTo(string2); if (result > 0) { System.Console.WriteLine("{0} is greater than {1}", string1, string2); } else if (result == 0) { System.Console.WriteLine("{0} is equal to {1}", string1, string2); } else if (result < 0) { System.Console.WriteLine("{0} is less than {1}", string1, string2); } // Outputs: ABC is less than abc 是这回事吗? |