ASP.NET Core MVC Interview Question #165

What is the difference between culture and UI culture?

Testing, AJAX/JavaScript Integration, Localization & Advanced MVC Senior Advanced

Quick Interview Answer

Culture primarily affects culture-sensitive formatting and parsing such as numbers, dates, and currency. UI culture is used to select localized resources for user-interface text.

Detailed Explanation

Culture primarily affects culture-sensitive formatting and parsing such as numbers, dates, and currency. UI culture is used to select localized resources for user-interface text.

They are often set to the same value, but they represent different concerns. Applications should avoid assuming that data-storage formats should follow the user's display culture; persistent data should use appropriate invariant or strongly typed representations.

Code Example

var culture = CultureInfo.CurrentCulture;
var uiCulture = CultureInfo.CurrentUICulture;

var formatted = amount.ToString("C", culture);