好吧问题是我对列表的计数没有上升所以它没有将对象添加到列表中.
List<Employee> employees = new List<Employee>();
private void addEmployee_Click(object sender, EventArgs e)
{
List<Employee> employees = new List<Employee>();
employees.Add(new Employee()
{
egn = egnInput.Text,
names = namesInput.Text,
proffesion = professionList.Text,
office = officeList.Text,
salary = Double.Parse(salaryInput.Text),
joinDate = DateTime.Parse(joinDatePicker.Text)
});
MessageBox.Show("????????? ?? ??????? ???????!");
egnInput.Clear();
namesInput.Clear();
professionList.Text = "";
officeList.Text = "";
salaryInput.Clear();
joinDatePicker.Text = "";
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!
因为你已经定义了List在addEmployee_Click事件,所以每次点击Button的List再次产生.您应该在addEmployee_Click事件中删除以下行,因为您已经全局声明了它:
List<Employee> employees = new List<Employee>();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
107 次 |
| 最近记录: |