-11
string a = "sea";  
string b = "SEA"
if (a == b)...

无论字符大小写如何,我怎么能说这两个字符串是相同的?

4

3 回答 3

7

使用字符串。比较:

http://msdn.microsoft.com/en-us/library/zkcaxw5y.aspx

if (string.Compare(a, b, true) == 0)
{
 ...
}
于 2012-07-02T13:51:06.540 回答
3
if (0 == String.Compare(a, b, true))...

http://msdn.microsoft.com/en-us/library/zkcaxw5y.aspx

于 2012-07-02T13:51:58.957 回答
2

使用String.Equals()并使用正确的 StringComparison-Value:

if(a.Equals(b, StringComparison.CurrentCultureIgnoreCase))
{
   ...//strings are equal
}

@OP:请遵循whathaveyoutried.com的指南并阅读文档... ...这样您就可以自己回答类似的问题,最终您将了解更多关于语言和技术的知识.. . :)

于 2012-07-02T13:53:33.593 回答