是否有任何全球化问题使用'=='运算符和string.Equals()方法来比较字符串?

Jam*_*eel 1 .net c# vb.net

是否存在使用' =='运算符和string.Equals()方法来比较字符串的全球化问题?如果是,避免这种情况的解决方案是什么?

Hab*_*bib 5

String.Equals,你可以使用StringComparison.InvariantCultureIgnoreCaseStringComparison.InvariantCulture,==你不能这样做.

您应该看到:土耳其语问题以及您应该关注的原因

来自同一篇文章的代码片段:

using System;
using System.Globalization;
using System.Threading;
internal class Program
{
    private static void Main(string[] args)
    {      
        Thread.CurrentThread.CurrentCulture = new CultureInfo("tr-TR");
        const string input = "interesting";

        bool comparison = input.ToUpper() == "INTERESTING";

        Console.WriteLine("These things are equal: " + comparison);
        Console.ReadLine();
    }
}
Run Code Online (Sandbox Code Playgroud)

以上将false使用==运算符返回a 进行相等比较

您可以在上面的代码中尝试以下行

 bool Comparison2 = input.Equals("INTERESTING",
                                  StringComparison.InvariantCultureIgnoreCase);
Run Code Online (Sandbox Code Playgroud)

结果将是 true