How can I align text in columns using Console.WriteLine?

前端 未结 8 1231
隐瞒了意图╮
隐瞒了意图╮ 2020-11-28 22:11

I have a sort of column display, but the end two column\'s seem to not be aligning correctly. This is the code I have at the moment:

Console.WriteLine(\"Cust         


        
8条回答
  •  独厮守ぢ
    2020-11-28 22:56

    Try this

    Console.WriteLine("{0,10}{1,10}{2,10}{3,10}{4,10}",
      customer[DisplayPos],
      sales_figures[DisplayPos],
      fee_payable[DisplayPos], 
      seventy_percent_value,
      thirty_percent_value);
    

    where the first number inside the curly brackets is the index and the second is the alignment. The sign of the second number indicates if the string should be left or right aligned. Use negative numbers for left alignment.

    Or look at http://msdn.microsoft.com/en-us/library/aa331875(v=vs.71).aspx

提交回复
热议问题