String.Format corresponds to each of the tokens inside the string ( {0} , etc.) for the corresponding object: http://msdn.microsoft.com/en-us/library/system.string.format.aspx
Additionally, a format string is provided:
{ index[,alignment][ : formatString] }
If formatString provided, the corresponding object must implement IFormattable and, in particular, the ToString method, which accepts formatString and returns the corresponding formatted string: http://msdn.microsoft.com/en-us/library/system.iformattable.tostring.aspx
IFormatProvider can also be used, which can be used to capture the basic formatting standards / default values, etc. Examples here and here .
So, the answers to your questions are in order:
It uses the IFormattable interface ToString() method for the DateTime object and passes a string of the format MM/dd/yyyy . This is an implementation that returns the correct string.
Any object that implements IFormattable supports this function. You can even write your own!
Yes, see above.
yamen May 9 '12 at 8:27 2012-05-09 08:27
source share