首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >字符串的c#格式错误

字符串的c#格式错误
EN

Stack Overflow用户
提问于 2018-10-23 03:08:39
回答 2查看 260关注 0票数 -2

我试图找出为什么当我运行我的程序并按下提交按钮时,我得到一个错误,说我的列表格式错误。关于这个程序的一些背景知识:它是为我的可视化编程课程准备的。这个程序是为银行账户准备的。我试着评论每一节是什么,以使它更容易阅读

代码语言:javascript
复制
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    //Tab 1 Create and close account
    private void Submitbtn_Click(object sender, EventArgs e)
    {
        double x;

        if (OpenRdo.Checked == true && Nametxtbx.TextLength > 0)
        {
            double.TryParse(Nametxtbx.Text, out x);

            // after clicking the button there is
            // no number; it says system.random
            Random acct = new Random();                
            int AccountNumber = acct.Next(5, 1000);
            outputlbl.Text = acct.ToString();
        }

        // list for accounts 
        // This is where it says I have the error
        // that my list is in the wrong format
        var accounts = new List<Account>
        {
            new  Account(Nametxtbx.Text, double.Parse(outputlbl.Text), 0)
        };

        // Write these records to a file
        WriteFile(accounts);

        // message box when you create account
        if (ValidateChildren(ValidationConstraints.Enabled))
        {
            MessageBox.Show("Account Created", "Message", 
                MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }

    //writing to the file
    static void WriteFile(List<Account> accts)
    {
        StreamWriter outputFile = File.CreateText("accounts.txt");
        string record;

        foreach (var acct in accts)
        {
            record = $"{acct.Name},{acct.Balance}";
            Console.WriteLine($"Writing record: {record}");
            outputFile.WriteLine(record);
        }

        outputFile.Close();
    }
}
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52936219

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档