Difference between CultureInfo.CreateSpecificCulture() and the constructor of the class?

The factory method has an fallback when it fails to create the culture info.

So if you use a specific culture like ‘en-XX’, the culture info instance can’t be created, an exception will throw and a retry with the neutral culture ‘en’ will succeed.

Below the source of the factory method

public static CultureInfo CreateSpecificCulture(string name)
{
    CultureInfo info;
    try
    {
        info = new CultureInfo(name);
    }
    catch (ArgumentException)
    {
        info = null;
        for (int i = 0; i < name.Length; i++)
        {
            if ('-' == name[i])
            {
                try
                {
                    info = new CultureInfo(name.Substring(0, i));
                    break;
                }
                catch (ArgumentException)
                {
                    throw;
                }
            }
        }
        if (info == null)
        {
            throw;
        }
    }
    if (!info.IsNeutralCulture)
    {
        return info;
    }
    return new CultureInfo(info.m_cultureData.SSPECIFICCULTURE);
}

So the I prefer the factory method.

Leave a Comment

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