我将如何构造PrintNode()方法?

时间:2016-08-23 08:21:16

标签: c# format doubly-linked-list

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

交易编号:

日期/////////////////////说明/////// DebitCredit /////金额

12345678:2012/01/15 abs a 100

我希望将值放入正确的位置。

12345678应该在Trasaction No:

2012/01/2015在日期

我将如何格式化? (对不起,如果这是一个可怕的问题。我还是新手),制定了这个方法,但我不知道怎么做" Prettify"它了。



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!";
            }

        }
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:2)

请尝试使用此代码段,然后查看差异

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!";
        }
    }