将TextBox输入存储到数组中

时间:2018-03-31 20:56:52

标签: c# arrays class

请原谅我,因为我是C#和编程的初学者。我正在创建一个基本表单应用程序(gui),用于在单击按钮(名称,姓氏等)后将用户提供的数据存储到某些TextBox中。而且我很难将这些信息存储到数组中。请注意,信息属于不同的类。                                                真诚的,一个编程初学者。

命名空间员工 {     班级员工     {         public int employeeID;         public string firstname;         public string lastname;         公共双薪;

    public Employee(int IDValue, string firstNameValue,
                     string lastNameValue, double salaryValue)
    {
        employeeID = IDValue;
        firstname = firstNameValue;
        lastname = lastNameValue;
        salary = salaryValue;
    }

    public int EmployeeID
    {
        get
        {
            return employeeID;
        }

        set
        {
            employeeID = value;
        }


    }

    public string FirstName
    {
        get
        {
            return firstname;
        }

        set
        {
            firstname = value;
        }


    }

    public string LastName
    {
        get
        {
            return lastname;
        }

        set
        {
            lastname = value;
        }


    }

    public double Salary
    {
        get
        {
            return salary;
        }

        set
        {
            salary = value;
        }


    }

    public string employeeToString()
    {
        return (Convert.ToString(employeeID) + " " + firstname +
                " " + lastname + " " + Convert.ToString(salary));
    }

}

}

1 个答案:

答案 0 :(得分:0)

可能是这样的:

         private void button1_Click(object sender, EventArgs e)
    {
        if (textBox1.Text.Length > 0)
        {
            label1.Text = string.Empty;
            string[] arr = textBox1.Text.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < arr.Length; i++)
                label1.Text += arr[i] + "\r\n";
        }
    }