How do culture and CultureInfo affect a .NET application?

.NET Framework & CLR Platform Intermediate 2–3 Yrs3–5 Yrs Debugging 1 min read

Quick Answer

CultureInfo.CurrentCulture controls how numbers, dates and currency are formatted and parsed for a thread; CurrentUICulture controls which localized resource strings load. A classic bug: parsing "1,234.56" or a date in a culture where the separators are different — always use CultureInfo.InvariantCulture for machine-readable data (files, APIs, config).

The current culture on a thread decides how numbers and dates format and parse — the decimal separator, the date order, the currency symbol. The bug I've seen most is calling decimal.Parse or DateTime.Parse on data that came from a file or an API without specifying a culture: it uses the server's culture, and a server set to a European locale reads 1.234 as one-thousand-two-hundred-thirty-four. So for anything machine-to-machine I always pass InvariantCulture or use an explicit ISO format, and only use the user's culture for what's actually displayed to them.

  • Format/parse for display → user's culture. Format/parse for storage/interchange → InvariantCulture (or an explicit ISO format).
  • double.Parse(s) uses the current culture by default — a server in a German locale reads . as a thousands separator.
  • ASP.NET Core: request localization middleware sets the culture per request from a cookie/header/query.
  • String comparison: StringComparison.Ordinal for identifiers/keys; culture-aware comparison only for user-visible sorting.