代码之家  ›  专栏  ›  技术社区  ›  Anon

如何构造PrintNode()方法?

  •  2
  • Anon  · 技术社区  · 9 年前

    目前这是我的PrintNode()方法,它给了我

    交易编号:

    日期/////////////////说明///////借记信贷/////金额

    12345678:2012年1月15日abs a 100

    我想把这些值放在正确的位置。

    12345678应在交易编号下:

    2012/01/2015以下日期

    我该如何格式化它?(如果这是一个可怕的问题,我很抱歉。我还是个新手),想出了方法,但我不知道如何“美化”它。

    public void PrintNodes(LinkedList<Transactions> values)
            {
                if (values.Count != 0)
                {
                    txtOutput.Text += "Transaction Details for Account No" + + ":" + "\r\n" + "Date\t\tDescription\tDebitCredit\tAmount";
    
                    foreach (Transactions t in values) 
                    {
                        txtOutput.Text += "\r\n" + t + "\t";
                        txtOutput.Text += "\t";
                    }
                    txtOutput.Text += "\r\n";
                }
                else
                {
                    txtOutput.Text += "The Doubly Linked List is empty!";
                }
    
            }
    1 回复  |  直到 9 年前
        1
  •  2
  •   Akram Qalalwa    9 年前

    public void PrintNodes(LinkedList<Transactions> values)
        {
            if (values != null && values.Count > 0)
            {
                int accountNumber = 1000001;
                StringBuilder builder = new StringBuilder();
                builder.Append($"Transaction Details for Account No. {accountNumber}");
                builder.Append(Environment.NewLine);
                builder.Append("Date\t\tDescription\t\tDebitCredit\t\tAmount");
                builder.Append(Environment.NewLine);
                foreach (Transactions t in values)
                {
                    builder.Append($"{t.Date}\t\t{t.Description}\t\t{t.DebitCard}\t\t{t.Amount}");
                    builder.Append(Environment.NewLine);
                }
                txtOutput.Text += builder.ToString();
            }
            else
            {
                txtOutput.Text = "The list is empty!";
            }
        }