我正在尝试格式化输出,以便在打印行时看起来像这样
Name Price
LongName Price
Name3 Price
我希望它看起来像一张桌子。这是我的代码
var byValue =
from i in invoices
let total = (i.Quantity * i.Price)
orderby total
select i.PartDescription + " " + total;
foreach (var element in byValue)
Console.WriteLine(element);
答案 0 :(得分:1)
您可以使用String.PadRight
:
select i.PartDescription.PadRight(maxLengthOfDescription) + total
如果您不知道最大长度,可以计算:
maxLengthOfDescription =
invoices.Max(invoice => invoice.PartDescription.Length) + 1