C# String comparisons: Difference between CurrentCultureIgnoreCase and InvariantCultureIgnoreCase

The other posts have given good advice, but I thought it might be nice to show an example of where it definitely makes a difference:

using System;
using System.Globalization;
using System.Threading;

class Test
{
    static void Main()
    {
        CultureInfo turkish = CultureInfo.CreateSpecificCulture("tr");
        Thread.CurrentThread.CurrentCulture = turkish;                

        // In Turkey, "i" does odd things
        string lower = "i";
        string upper = "I";
        
        // Prints False
        Console.WriteLine(lower.Equals(upper, 
            StringComparison.CurrentCultureIgnoreCase));
        // Prints True
        Console.WriteLine(lower.Equals(upper, 
            StringComparison.InvariantCultureIgnoreCase));
    }
}

(There are no doubt many other cases – this was just the first one I thought of.)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)