【问题】
C#中,有个变量,为int型的4,想要格式化输出为04,相当于普通C语言中的printf中的%02d。
【解决过程】
1.已经找到之前的关于C#中的类似于printf中的用法了:string spritfTestStr = String.Format("Test sprintf in C#, number={0:D}, string=\"{1:s}\", float={2:0.000}", 100, "crifan", Math.PI);
//spritfTestStr = Test sprintf in C#, number=100, string="crifan", float=3.142
但是,此处尝试着写了多种方式:{0:2D}
{0:02D}
{0:02d}
竟然都还是无法正常输出我要的%02d的效果。Format specifier
Name
Description
0
Zero placeholder
If the value being formatted has a digit in the position where the ‘0’ appears in the format string, then that digit is copied to the result string. The position of the leftmost ‘0’ before the decimal point and the rightmost ‘0’ after the decimal point determines the range of digits that are always present in the r