asp.net.ph

Skip Navigation LinksHome > Getting Started > ASP.NET Base Types > Format Specifiers and Providers

Format Specifiers and Providers

Getting Started   ASP.NET Base Types


Format Specifiers

Format specifiers, or format strings, are one or more characters that are used to specify the kind of formatting to apply when a base type is represented as a string.

Basically, a format string can be used in conjunction with any of the available formatting methods ( see Formatting Base Types ). A format specifier can be passed as a parameter by itself, or used in conjunction with a given format provider, to more precisely control how formatting is to be applied.

Format specifiers fall into either of two categories: standard format strings and custom format strings.

Standard format strings are those predefined by the .NET Framework for use by specific types, while custom format strings are supplied in cases where the standard format specifiers do not provide the type of formatting required.

The .NET Framework provides the following set of format specifiers.


Format Providers

Format providers define type- and culture-specific formatting models and norms, such as the calendar in use, date patterns, day and month names, decimal separators, currency symbols, and the like, that govern how the runtime renders numeric and datetime types, based on the current or a specified culture.

Basically, a format provider can be used in conjunction with any of the available formatting methods ( see Formatting Base Types ). A format provider can be passed as a parameter by itself, or used in conjunction with a given format string, to more precisely control how formatting is to be applied.

By default, the .NET framework base types are formatted using standard or custom patterns stored as properties in the following classes.

  • DateTimeFormatInfo, which defines how date and time values are formatted and displayed.
  • NumberFormatInfo, which defines how numeric values are formatted and displayed.
  • CultureInfo, which defines culture-specific information, such as the associated language, sublanguage, country/region, calendar, and cultural conventions. This class also provides access to culture-specific instances of DateTimeFormatInfo and NumberFormatInfo.

In cases where formatting information is needed but no format provider is passed, the information is obtained from the CultureInfo object associated with the current thread.

Any class that implements the IFormatProvider interface can be used as a format provider. This means that developers can programmatically define custom formatting schemes for custom types or cultural settings. For information on creating custom format schemes, see Customizing Format Strings.

See Also

Formatting Base Types | Converting Types | Parsing Strings



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note