1

我正在尝试将项目移动到列表框,但它将我的列表框称为方法组。该程序有多个类。这是我目前所拥有的...

private void Button1_Click(object sender, EventArgs e)
{
    ListBox1.Items.Add("Full Name\tAddress\tPhone Number");

    Person Customer = new Person();
    Customer.FirstName = NameTextBox.Text;
    Customer.LastName = NameTextBox2.Text;
    Customer.Address = AddressTextBox.Text + AddressTextBox2.Text + AddressTextBox3.Text;
    Customer.PhoneNumber = PhoneNumberMaskedTextBox.Text;

    Listbox1.Items.Add = (Customer.FirstName + Customer.LastName + "/t" + Customer.Address + "/t" + Customer.PhoneNumber);
}

人是另一个类。这是代码...

class Person
{
    string _FirstName;
    string _LastName;
    string _Address;
    string _PhoneNumber;

    //Constructor
    public void CustomerInfo()
    {
        _FirstName = "";
        _LastName = "";
        _Address = "";
        _PhoneNumber = "";
    }

    public string FirstName           
    {
      get { return _FirstName; }
      set { _FirstName = value; }
    }

    public string LastName
    {
      get { return _LastName; }
      set { _LastName = value; }
    }

    public string Address
    {
      get { return _Address; }
      set { _Address = value; }
    }

    public string PhoneNumber
    {
        get { return _PhoneNumber; }
        set { _PhoneNumber = value; }
    }
}
4

1 回答 1

2

在你的第二个Add电话中,你可能想要

Listbox1.Items.Add(...)

代替

Listbox1.Items.Add = (

您的代码中其他不正确的地方是Person. 它应该被命名Person,因为构造函数与类具有相同的名称。

于 2013-05-06T18:33:51.087 回答