在Console.WriteLine方法格式字符串字符串、格式、方法、Console

由网友(堇年)分享简介:林新的C#编程。是否有人可以解释以下code:Im new to C# programming. Can someone please explain the following code:Console.WriteLine( "{0}{1,10}", "Face", "Frequency" ); //Headin...

林新的C#编程。是否有人可以解释以下code:

Im new to C# programming. Can someone please explain the following code:

Console.WriteLine( "{0}{1,10}", "Face", "Frequency" ); //Headings
Console.WriteLine( "{0,4}{1,10}",someval,anotherval);

据我所知,这个打印给定标题值的两列,而 {0} 是指给定的第一个参数。但是,什么是形式 {X,Y}

I understand that this prints two columns of values with the headings given, and {0} refers to the first argument given. But what is the meaning of the format strings of the form {x,y} ?

请帮助 谢谢

推荐答案

它增加了填充到左边。为记住不同的字符串格式化方式非常有用的是下面的备忘单:

It adds padding to the left. Very useful for remembering the various string formatting patterns is the following cheat sheet:

.NET的String.Format小抄

.NET String.Format Cheat Sheet

正值添加填充到左侧,负添加填充到右侧

Positive values add padding to the left, negative add padding to the right


Sample                                 Generates
String.Format("[{0, 10}]", "Foo");     [∙∙∙∙∙∙∙Foo]
String.Format("[{0, 5}]", "Foo");      [∙∙Foo]
String.Format("[{0, -5}]", "Foo");     [Foo∙∙]
String.Format("[{0, -10}]", "Foo");    [Foo∙∙∙∙∙∙∙]
阅读全文

相关推荐

最新文章