// The previous editor was originally intended to be re-edited, but it was changed back to the Tiny MCE editor after I adjusted it to Markdown.
1. Format (), ToString () method & IFormattable & IFormatProvider
First, ToString (). Four ToString methods are defined in System. Int32.
1. The ToString () with no parameter is used to override the Object, (or ValueType)
2, 3, and 4 are used in the same way. The third one can customize the Provider.
Int implements the IFormattable interface.
Only one ToString method, format parameter, and provider of the IFormatProvide type are defined in IFormattable.
There are only a few types of IFormatProvider implemented in. NET, including SystemGlobalzation. CultureInfo
IFormatProvider defines a GetFormat method (type) to obtainSystem. GlobalizationIn the namespaceNumberFormatInfoAndDateTimeFormatInfoInstance,
These two classes, like CultureInfo, are also instances of the IFormatProvider, because currently. NET involves internationalization operations, numbers, and dates. numberFormatInfo and DateTimeFormatInfo. If you want to get the date, you need to format the number. the excerpt from DateTimeFormatInfo is as follows. It also includes Chinese, Japanese, and other related content.
DateTimeFormatInfo, NumberFormatInfo is an IFormatProvider instance. Their GetFormat method returns this or null Based on the type parameter.
Instance:
I = Console. writeLine (I. toString (); Console. writeLine (I. toString (); Console. writeLine (I. toString (); Console. writeLine (I. toString (); Console. writeLine (I. toString (, System. globalization. cultureInfo. invariantCulture); Console. writeLine (I. toString (, System. globalization. cultureInfo ()));}View Code
ToString (), ToString (format) are actually equivalent to calling ToString (format, provider) version,
When the first parameter is null, the default value is null or "G" (generally)
If the second miserable parameter is null, the regional cultural information of the currently called Thread is obtained based on System. Globalization. CultureInfo. CurrentCulture or System. Threading. Thread. CurrentThread. CurrentCulture.
2. About String. Fornat, StringBuilder. AppendFormat
String. format (format, param object [] arg), such as String. format ("The Post with id equals {0: x4} is wiite on {1}", 1, DateTime. now)
When the Format method encounters a tag such as {0}, it will call the ToString (format) of arg based on the format following the colon. At the same time, the Format overload allows the passing of a custom Provider
The following uses the example on CLR via C # To write a custom IFormatProvider. function: output the char type according to unicode
The result is displayed
Code
(FormatType = Format (format, str = (arg. GetType () = () & format! =) (Format = str = + () arg )). toString (format = str = + () arg )). toString (arg IFormattable) str = (arg IFormattable ). toString (format, (arg! = Str =}View Code
It's a bit late today. I will try again later ~~~