Formatting a string with string.Format(“{0:00}”

后端 未结 1 1356
小蘑菇
小蘑菇 2021-02-12 07:54

I have just taken over some code and I see this used a lot. It seems to take the integer and create a string looking like \"01\", \"02\" etc.

What I am not sure of is t

相关标签:
1条回答
  • 2021-02-12 08:14

    The first 0 is the placeholder, means the first parameter. 00 is an actual format.

    For example it could be like this:

    var result = string.Format("{0:00} - {1:00}", 5, 6);
    

    result will be 05 - 06. So the first 0 is means take the first parameter 5, while 1 means to take parameter 6.

    The format is {index[,length][:formatString]}. Take a look at String.Format Method.

    0 讨论(0)
提交回复
热议问题