Home > Net > How can expression, passed as a parameter
How can expression, passed as a parameter
Time:11-18
In c #, can expression, passed as a parameter?
In the following method, for example, if the expression of actual can be very complex, changeable, need to change according to the content of the key value, should be how to deal with right now? Thank you
private void Test () { DataGridView. Rows. The Clear (); Foreach (var name in dic. Keys) { If (name. StartsWith (" Final ") | | name. StartsWith (" Sub "))//here should be how to design to satisfy different needs? { Int rowIndex=dataGridView. Rows. The Add (); Foreach (DataGridViewColumn column in dataGridView. Columns) { DataGridViewCell currentCell=dataGridView. Rows [rowIndex] Cells [column. The Index]; CurrentCell. Value=https://bbs.csdn.net/topics/dic [name]; } } } }
CodePudding user response:
The test ( func Func { DataGridView. Rows. The Clear (); Foreach (var name in dic. Keys) { If ( func (name))//here should be how to design to satisfy different needs? { Int rowIndex=dataGridView. Rows. The Add (); Foreach (DataGridViewColumn column in dataGridView. Columns) { DataGridViewCell currentCell=dataGridView. Rows [rowIndex] Cells [column. The Index]; CurrentCell. Value=https://bbs.csdn.net/topics/dic [name]; } } } }
Simple demonstration, of course I didn't judge whether he is null, here yourself
CodePudding user response:
Learn express Or the func (), action (), etc. Express Build the expression tree, Common memory directly manipulate data, can use the func
The following figure illustrates the, 1 set Func the condition of2 myList invokes the where clause, add 1 the condition of