List <t> .Add不添加到列表中

时间:2017-02-18 14:41:37

标签: c# winforms

问题是我对列表的计数没有上升,所以它没有将对象添加到列表中。

def welch_ttest(x1, x2):
    x_1 = x1.mean()
    x_2 = x2.mean()
    s1 = x1.std()
    s2 = x2.std()
    n1 = len(x1)
    n2 = len(x2)
    return ((x_1 - x_2) / (np.sqrt(s1 ** 2 / n1 + s2 ** 2 / n2)))

def grouped_welch_ttest(df):
    return welch_ttest(df.key2, df.key3)

df1.groupby('key1').apply(grouped_welch_ttest)

key1
0   -1.471497
1    1.487045
dtype: float64

提前致谢!

2 个答案:

答案 0 :(得分:7)

由于您已在addEmployee_Click事件中定义了Button,因此每次点击List时,都会再次创建addEmployee_Click。您应该删除List<Employee> employees = new List<Employee>(); 事件中的以下行,因为您已经全局声明了它:

procedure TForm1.Button1Click(Sender: TObject);
begin
ODBCConnection1.DatabaseName:='LazConnect';
ODBCConnection1.UserName:='Admin';
ODBCConnection1.Transaction:=SQLTransaction1;
SQLTransaction1.Database:=ODBCConnection1;
SQLQuery1.Database:=ODBCConnection1;
SQLQuery1.Transaction:=SQLTransaction1;
SQLQuery1.UsePrimaryKeyAsKey:=False;
SQLQuery1.SQL.Text:='SELECT * FROM Student';
Datasource1.dataset:=SQLQuery1;
DBGrid1.DataSource:=DataSource1;
ODBCConnection1.Open;
If ODBCConnection1.Connected then
end;   

答案 1 :(得分:0)

不要在addEmployee_Click内定义列表,而是将其设为全局,如下所示:

List<Employee> employees = new List<Employee>(); // make this global to the class

private void addEmployee_Click(object sender, EventArgs e)
{
    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 = "";
}