Hello. There is a main form, in it DataGridView, I want to fill it with numbers in the stream created by me. Is it possible to pass lambda from several operators as a parameter of a method (in this case, a constructor)? I know that you can declare a delegate before the constructor and pass a variable containing an object reference. In my opinion it seems so beautiful, but this option is wrong.

private void SetData(object number) { DataTable.Invoke(new Action<int>(n => { DataTable.RowCount = n; for (int i = 0; i < n; i++) { DataTable.Rows[i].Cells[0].Value = i.ToString(); DataTable.Update(); } };), (int)number); } private void StartButtonClick(object sender, EventArgs e) { Thread thread = new Thread(SetData); thread.Start(10000); } 
  • What does wrong mean? - Qwertiy
  • It is not compiled by the studio, so it is impossible to write (as in the example) - NordeN
  • I have already answered ... - Qwertiy

1 answer 1

Take a semicolon and should earn. Although I would have cut out a new Action.