我想做的是使通过 Console.Writeline 方法输出的文本完美排列,无论长度如何。
Example:
// Notice that no matter the length of the text on the left,
// the text on the right is always spaced at least 5 spaces.
this is output text
this is also output text
output text
my output text
我是否必须为此编写自己的方法,或者 .Net 是否包含我已经可以使用的东西?
而是用 Linq 来思考!
var outputs = new List<string>() {
"this is output",
"this is also output",
"output",
"my output"
};
var size = outputs.Max (str => str.Length) + 5;
Console.WriteLine (
string.Join(Environment.NewLine,
outputs.Select (str => str.PadRight( size ) + "Text" ) )
);
/*
this is output Text
this is also output Text
output Text
my output Text
*/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)