gpt4 book ai didi

c# - 字符串格式参数中的逗号

转载 作者:行者123 更新时间:2023-11-30 22:08:40 25 4
gpt4 key购买 nike

我遇到了 ToString() 方法的以下实现:

return string.Format("${0}.{1,2:00}", dollars, cents);

我无法理解此处使用的第二个命令行参数,即 {1,2:00}有人可以解释一下这些参数中 , 的用法吗?

最佳答案

参见文档 Composite Formatting ,并尝试例如:

result = string.Format("We have '{0,6}' with positive", 3.14);

result = string.Format("We have '{0,-6}' with negative", 3.14);

引用自链接页面:

The optional alignment component is a signed integer indicating the preferred formatted field width. If the value of alignment is less than the length of the formatted string, alignment is ignored and the length of the formatted string is used as the field width. The formatted data in the field is right-aligned if alignment is positive and left-aligned if alignment is negative. If padding is necessary, white space is used. The comma is required if alignment is specified.

关于c# - 字符串格式参数中的逗号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22114499/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com