4

Is the ":s" in this expression string.format("{0:s}", "hello world") just mean that the variable is a string? I'm just not sure why anyone would ever do this.

I found this in code and would like to remove the ":s" but want to be sure that I'm not altering behavior.

4

1 回答 1

6

它是标准日期和时间格式字符串的可排序说明符

在你的情况下(打印一个字符串)我认为它对输出没有影响

说明符作用于 DateTime 值,将其转换为适合排序的显示格式。
例如调用此代码

 string result = string.Format("-{0:s}-", DateTime.Now);
 Console.WriteLine(result)

将打印

2013-09-04T19:27:56
于 2013-09-04T17:23:25.460 回答