IFormatProvider Interface
Summary
Defines a mechanism that returns an object that customizes formatting or parsing of the current natural language or cultural information.
Inheritance
Members
Methods
Remarks
The IFormatProvider
interface is implemented by classes that supply culture-specific formatting information. For example, DateTimeFormatInfo
and NumberFormatInfo
are culture-specific classes that implement IFormatProvider
and provide formatting information for dates, times, and numbers.
Many methods in the .NET Framework that format or parse data, such as the overloads of ToString()
and Parse()
, accept an IFormatProvider
object as a parameter. This allows you to specify how the data should be formatted or parsed according to the conventions of a particular culture.
If you do not specify an IFormatProvider
, the current culture's formatting information is used. This can lead to unexpected results if your application is deployed to computers with different regional settings.
To obtain an IFormatProvider
for a specific culture, you can use the static properties of the CultureInfo
class (e.g., CultureInfo.InvariantCulture
, CultureInfo.CurrentCulture
) or create a new CultureInfo
object (e.g., new CultureInfo("fr-FR")
).