有人能告诉我这是什么意思 WriteLine(“{0,-12}”)
{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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
“{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
来自 msdn
from msdn
它用于字符串对齐。
http://www.csharp-examples.net/align-string-with -空格/
It is for string alignment.
http://www.csharp-examples.net/align-string-with-spaces/
格式说明符的 -12 部分告诉格式化程序将内容写入 12 个字符宽的空间并左对齐。如果内容少于12个字符,最右边的位置将用空格填充。如果超过 12 个字符,文本就会溢出。我猜测该示例正在尝试制作格式整齐的柱状数据:
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: