0

我正在尝试格式化输出,以便在打印行时看起来像这样

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);
4

1 回答 1

1

您可以使用String.PadRight

select i.PartDescription.PadRight(maxLengthOfDescription) + total

如果你不知道最大长度,你可以计算它:

maxLengthOfDescription =
    invoices.Max(invoice => invoice.PartDescription.Length) + 1
于 2013-10-06T06:00:15.327 回答