有人能告诉我这是什么意思 WriteLine(“{0,-12}”)

发布于 2024-08-29 07:59:40 字数 203 浏览 4 评论 0原文

{0,-12} 是我好奇的部分..

我正在看这个例子

    Console.WriteLine("{0,-12} {1}", sqlReader.GetName(0),
                                         sqlReader.GetName(1));

干杯:)

{0,-12} is the part i'm curious about..

I'm looking at this example

    Console.WriteLine("{0,-12} {1}", sqlReader.GetName(0),
                                         sqlReader.GetName(1));

Cheers :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

十雾 2024-09-05 07:59:40

“{0,-12}”的“0”部分表示采用第一个参数 (sqlReader.GetName(0))。 “-12”部分表示字符串应左对齐,并且应使用 12 个空格(字段宽度)。如果数据没有使用全部 12 个空格,它将填充剩余的空格,使字符串的总宽度为 12。

您可以在此处查看所有选项:http://msdn.microsoft.com/en-us/library/txafckwd.aspx

The "0" part of "{0,-12}" says to take the first argument (sqlReader.GetName(0)). The "-12" part indicates that the string should be left-aligned, and that it should use 12 spaces (the field width). If the data doesn't use all 12 spaces, it will fill in the remaining spaces to make the string a total width of 12.

You can see all the options here: http://msdn.microsoft.com/en-us/library/txafckwd.aspx

财迷小姐 2024-09-05 07:59:40

来自 msdn

{索引[,长度][:格式字符串]}

长度:
中的最小字符数
的字符串表示形式
范围。如果为正,则参数
是右对齐的;如果为负,则为
左对齐。

from msdn

{index[,length][:formatString]}

length:
The minimum number of characters in
the string representation of the
parameter. If positive, the parameter
is right-aligned; if negative, it is
left-aligned.

七七 2024-09-05 07:59:40

格式说明符的 -12 部分告诉格式化程序将内容写入 12 个字符宽的空间并左对齐。如果内容少于12个字符,最右边的位置将用空格填充。如果超过 12 个字符,文本就会溢出。我猜测该示例正在尝试制作格式整齐的柱状数据:

0123456789012345678901234567890
ShortText   OtherData
LongerText  OtherData
ReallyLongTextOtherData

The -12 part of the format specifier tells the formatter to write the content in a space 12 characters wide with left-justification. If the content is fewer than 12 characters, the rightmost positions will be filled with spaces. IF it's more than 12 characters, the text will just spill over. I'm guessing that the example is trying to make neatly formatted columnar data:

0123456789012345678901234567890
ShortText   OtherData
LongerText  OtherData
ReallyLongTextOtherData
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文