Udostępnij za pośrednictwem


Formatting Types

The .NET Framework provides a consistent, flexible, and comprehensive means for you to represent any of the numeric, enumeration, and date and time base data types as a string. Formatting is controlled by strings of format specifier characters that indicate how a base type value is to be represented. For example, format specifiers indicate whether a formatted number should be represented in scientific notation, or whether a formatted date should present the month as a number or a name.

The .NET Framework also uses cultural settings to represent a base type in a form appropriate to a particular culture. You can supply custom cultural settings, or use the default cultural setting associated with the current thread. For example, when formatting a currency type, the cultural setting specifies the characters to use for the currency symbol, group separator, and decimal separator.

The .NET Framework allows you to define custom formatting schemes and custom cultural settings. This ability enables you to expand the formatting schemes of existing base types to accommodate custom scenarios, or create custom formatting schemes for custom types.

In This Section

  • Formatting Overview
    Provides an overview of how the base class library implements formatting, how to format numeric types, how to format string types, and how to format for a specific culture.

  • Composite Formatting
    Describes how to embed one or more formatted values in a string. The string can subsequently be displayed on the console or written to a stream.

  • Numeric Format Strings
    Describes standard and custom format strings used to create string representations of numeric types.

  • Date and Time Format Strings
    Describes standard and custom format strings used to create string representations of DateTime types.

  • Enumeration Format Strings
    Describes standard format strings used to create string representations of enumeration types.

  • Customizing Format Strings
    Provides information about performing your own interpretation of format strings, or adding custom format strings to custom or existing types.

  • Formatting How-to Topics
    Lists topics that provide step-by-step instructions for performing specific formatting operations.

  • Basic String Operations
    Explains how to manipulate strings using several methods in the String and StringBuilder classes.

  • Parsing Strings
    Describes how to initialize objects to the values described by string representations of those objects. Parsing is the inverse operation of formatting.