Saturday, August 13, 2011

When Are The Letters “F” and “G” Are Considered Equal

A friend of mine noticed an unusual anomaly whilst writing a .NET app which was using the Welsh (cy-GB) culture. Here’s a snippet:

public class Program
    static void Main(string[] args)
        var cultureInfo = new CultureInfo("cy-GB");

        Thread.CurrentThread.CurrentCulture = cultureInfo;
        Thread.CurrentThread.CurrentUICulture = cultureInfo;

        Console.WriteLine(String.Equals("f", "g", StringComparison.CurrentCultureIgnoreCase));
You would expect “f” and “g” to be different, however in this universe they are considered the same! A quick rummage around the Google attic revealed this Microsoft Connect report where someone else has reported the same problem. Microsoft have acknowledged this to be a bug in the framework, which will be resolved in the next version. In the meantime, I’m not aware of any straightforward workarounds other then having to specifically cater for the letter’s “f” and “g” in your code when doing any comparisons. That’s a bit crap Sad smile