CKTIS / C#
CultureInfo — culture for formatting and parsing
System.Globalization.CultureInfo describes cultural rules used for tasks such as formatting and parsing numbers and dates. Passing a culture explicitly separates user-facing presentation from stable textual data storage.
Version: .NET 10; repository net10.0 and LangVersion=preview; feature versions require per-entry verification
Syntax
CultureInfo culture = CultureInfo.InvariantCulture;
NumberFormatInfo numbers = culture.NumberFormat;
DateTimeFormatInfo dates = culture.DateTimeFormat;System.Globalization.CultureInfo represents a culture: a set of rules associated with a language and region. It implements IFormatProvider, so you can pass it to appropriate ToString and Parse overloads. Many overloads without an explicit provider use CultureInfo.CurrentCulture, making their results dependent on the user's environment.
CultureInfo.NumberFormat exposes NumberFormatInfo: decimal and grouping separators and rules for numbers, currencies, and percentages. CultureInfo.DateTimeFormat exposes DateTimeFormatInfo: date and time patterns, month and day names, and calendar settings. These are settings objects, not formatted strings. You can also pass them directly as providers for the corresponding operations.
CultureInfo.InvariantCulture is independent of a particular country and user settings. It suits a stable, agreed textual format; choose the appropriate user culture for human-facing presentation. Culture alone does not define a complete interchange format: specify the pattern and parsing rules too. Regional culture data can differ across platforms and updates.
CultureInfo.InvariantCulture is read-only. Attempting to change its NumberFormat, DateTimeFormat, or their settings throws InvalidOperationException. To customize settings, use (CultureInfo)CultureInfo.InvariantCulture.Clone(); the clone also contains copies of both formatting objects.
The example explicitly uses both providers. F2 produces two decimal places without grouping, while yyyy-MM-dd fixes the order of the date components. The code targets .NET 10 and does not require preview language features.
Examples
using System;
using System.Globalization;
CultureInfo culture = CultureInfo.InvariantCulture;
NumberFormatInfo numbers = culture.NumberFormat;
DateTimeFormatInfo dates = culture.DateTimeFormat;
decimal amount = decimal.Parse("1234.50", numbers);
DateTime date = new DateTime(2026, 2, 3);
Console.WriteLine(amount.ToString("F2", numbers));
Console.WriteLine(date.ToString("yyyy-MM-dd", dates));
Console.WriteLine(numbers.NumberDecimalSeparator);Result
1234.50 2026-02-03 .
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.