Zhanbo Sun [MS]

Realize .NET & Windows Vista Potential

February 2006 - Posts

  • Just .NET (1): CurrentCulture or CurrentUICulture as IFormatProvider in String.Format()?

    Filed under:

    Either Thread.CurrentCulture or Thread.CurrentUICulture can serve as value for the first parameter in String.Format Method (IFormatProvider, String, Object[]). But they are not interchangeable. We should use Thread.CurrentCulture here instead of Thread.CurrentUICulture.

    The .NET Framework uses the terminology “culture” to represent what might have traditionally been called the “locale”. The .NET Framework has two concepts of the active culture.
    UICulture, which is indicated by the Thread.CurrentUICulture property, corresponds to the language of the OS by default, or the selected language on a multi-language version of Windows. This affects which resources get loaded, so it determines which strings and pictures the user sees.

    CurrentUICulture is used almost exclusively for loading resources through the resource manager. If you don’t specify a culture to the resource manager, it defaults to CurrentUICulture.

    Culture, which is indicated by the Thread.CurrentCulture property, corresponds to the selection in Regional Options in the control panel by default. CurrentCulture affects how numbers, dates and times are formatted, and this is also what determines which sorting and casing rules to use.

    For String.Format(), it should use CurrentCulture. Since users are most comfortable in their own culture, CurrentCulture helps ensure that information is presented to users in the format they most prefer.